Commit 3ac34514 3ac34514101568995c11816836ccffffd46e1888 by Matthew DuVall

Add docs and throw exception when type is invalid, test coverage

1 parent d3b876ec
......@@ -160,9 +160,9 @@ Asserts that a given subject is `falsy <http://11heavens.com/falsy-and-truthy-in
``assertField()``
-------------------------------------------------------------------------------
**Signature:** ``assertField(String|object input, String expected[, String message, Object options])``
**Signature:** ``assertField(String|Object input, String expected[, String message, Object options])``
Asserts that a given form field has the provided value::
Asserts that a given form field has the provided value with input name or :ref:`selector expression <selectors>`::
casper.test.begin('assertField() tests', 1, function(test) {
casper.start('http://www.google.fr/', function() {
......
......@@ -450,6 +450,7 @@ Tester.prototype.assertEvalEqual = function assertEvalEquals(fn, expected, messa
};
function baseFieldAssert(inputName, expected, actual, message) {
/*jshint validthis:true */
"use strict";
return this.assert(utils.equals(actual, expected), message, {
......@@ -503,6 +504,8 @@ Tester.prototype.assertField = function assertField(input, expected, message, op
return this.assertFieldCSS(input.path, expected, message);
case 'xpath':
return this.assertFieldXPath(input.path, expected, message);
default:
throw new CasperError('Invalid regexp.');
// no default
}
}
......
......@@ -170,6 +170,25 @@ casper.test.begin('Tester.assertField(): XPath selectors', 1, function(test) {
});
});
casper.test.begin('Tester.assertField(): invalid selectors', 1, function(test) {
casper.start('tests/site/form.html', function() {
this.fill('form[action="result.html"]', {
'email': 'albert@camus.com'
});
test.assertRaise(function() {
test.assertField({
type: 'albert'
},
'albert@camus.com',
'Tester.assertField() works as expected with XPath selectors'
);
}, [], 'should throw an error for an invalid selector');
}).run(function() {
test.done();
});
});
casper.test.begin('Tester.assertFieldCSS(): CSS selectors', 1, function(test) {
casper.start('tests/site/form.html', function() {
this.fill('form[action="result.html"]', {
......@@ -200,4 +219,4 @@ casper.test.begin('Tester.assertFieldXPath(): XPath selectors', 1, function(test
}).run(function() {
test.done();
});
});
\ No newline at end of file
});
......