Commit 06d091f8 06d091f8c8ce5519a3f4681fc6e9fc604a705155 by Nicolas Perriault

added Tester.assert{Truthy|Falsy}()

1 parent 125c37f0
......@@ -95,6 +95,7 @@ Also, `Casper.mouseEvent()` will now directly trigger an error on failure instea
- fixed [`utils.betterTypeOf()`](http://casperjs.org/api.html#casper.betterTypeOf) to properly handle `undefined` and `null` values
- fixed `Casper.die()` and `Casper.evaluateOrDie()` were not printing the error onto the console
- added JSON support to `require()`
- added [`Tester.assertTruthy()`](http://casperjs.org/api.html#tester.assertTruthy) and [`Tester.assertFalsy()`](http://casperjs.org/api.html#tester.assertFalsy)
- added [`Casper.sendKeys()`](http://casperjs.org/api.html#casper.sendKeys) to send native keyboard events to the element matching a given selector
- added [`Casper.getFormValues()`](http://casperjs.org/api.html#casper.getFormValues) to check for the field values of a given form
- added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist)
......
Subproject commit f4720fa8946c88df0404b6f9c4790ca2d43826ac
Subproject commit 3de9f06fea80caffea1d73b71d20567458eba03e
......
......@@ -487,6 +487,44 @@ Tester.prototype.assertTextExists = Tester.prototype.assertTextExist = function
};
/**
* Asserts a subject is truthy.
*
* @param Mixed subject Test subject
* @param String message Test description
* @return Object An assertion result object
*/
Tester.prototype.assertTruthy = function assertTruthy(subject, message) {
"use strict";
/*jshint eqeqeq:false*/
return this.assert(utils.isTruthy(subject), message, {
type: "assertTruthy",
standard: "Subject is truthy",
values: {
subject: subject
}
});
};
/**
* Asserts a subject is falsy.
*
* @param Mixed subject Test subject
* @param String message Test description
* @return Object An assertion result object
*/
Tester.prototype.assertFalsy = function assertFalsy(subject, message) {
"use strict";
/*jshint eqeqeq:false*/
return this.assert(utils.isFalsy(subject), message, {
type: "assertFalsy",
standard: "Subject is falsy",
values: {
subject: subject
}
});
};
/**
* Asserts that given text exists in the provided selector.
*
* @param String selector Selector expression
......
......@@ -287,6 +287,18 @@ function isClipRect(value) {
exports.isClipRect = isClipRect;
/**
* Checks that the subject is falsy.
*
* @param Mixed subject Test subject
* @return Boolean
*/
function isFalsy(subject) {
"use strict";
/*jshint eqeqeq:false*/
return subject == new Function('return false;')();
}
exports.isFalsy = isFalsy;
/**
* Checks if value is a javascript Function
*
* @param mixed value
......@@ -372,6 +384,19 @@ function isString(value) {
exports.isString = isString;
/**
* Checks that the subject is truthy.
*
* @param Mixed subject Test subject
* @return Boolean
*/
function isTruthy(subject) {
"use strict";
/*jshint eqeqeq:false*/
return subject == new Function('return true;')();
}
exports.isTruthy = isTruthy;
/**
* Shorthands for checking if a value is of the given type. Can check for
* arrays.
*
......
......@@ -43,6 +43,12 @@ casper.thenOpen('tests/site/index.html', function() {
t.comment('Tester.assertTrue()');
t.assertTrue(true, 'Tester.assertTrue() works as expected [alias]');
t.comment('Tester.assertTruthy()');
t.assertTruthy('1', 'Tester.assertTruthy() works as expected');
t.comment('Tester.assertFalsy()');
t.assertFalsy('0', 'Tester.assertFalsy() works as expected');
t.comment('Tester.assertNot()');
t.assertNot(false, 'Tester.assertNot() works as expected');
......@@ -205,5 +211,5 @@ casper.then(function() {
});
casper.run(function() {
t.done(56);
t.done(58);
});
......