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 ...@@ -95,6 +95,7 @@ Also, `Casper.mouseEvent()` will now directly trigger an error on failure instea
95 - fixed [`utils.betterTypeOf()`](http://casperjs.org/api.html#casper.betterTypeOf) to properly handle `undefined` and `null` values 95 - fixed [`utils.betterTypeOf()`](http://casperjs.org/api.html#casper.betterTypeOf) to properly handle `undefined` and `null` values
96 - fixed `Casper.die()` and `Casper.evaluateOrDie()` were not printing the error onto the console 96 - fixed `Casper.die()` and `Casper.evaluateOrDie()` were not printing the error onto the console
97 - added JSON support to `require()` 97 - added JSON support to `require()`
98 - added [`Tester.assertTruthy()`](http://casperjs.org/api.html#tester.assertTruthy) and [`Tester.assertFalsy()`](http://casperjs.org/api.html#tester.assertFalsy)
98 - added [`Casper.sendKeys()`](http://casperjs.org/api.html#casper.sendKeys) to send native keyboard events to the element matching a given selector 99 - added [`Casper.sendKeys()`](http://casperjs.org/api.html#casper.sendKeys) to send native keyboard events to the element matching a given selector
99 - added [`Casper.getFormValues()`](http://casperjs.org/api.html#casper.getFormValues) to check for the field values of a given form 100 - added [`Casper.getFormValues()`](http://casperjs.org/api.html#casper.getFormValues) to check for the field values of a given form
100 - added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist) 101 - added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist)
......
1 Subproject commit f4720fa8946c88df0404b6f9c4790ca2d43826ac 1 Subproject commit 3de9f06fea80caffea1d73b71d20567458eba03e
......
...@@ -487,6 +487,44 @@ Tester.prototype.assertTextExists = Tester.prototype.assertTextExist = function ...@@ -487,6 +487,44 @@ Tester.prototype.assertTextExists = Tester.prototype.assertTextExist = function
487 }; 487 };
488 488
489 /** 489 /**
490 * Asserts a subject is truthy.
491 *
492 * @param Mixed subject Test subject
493 * @param String message Test description
494 * @return Object An assertion result object
495 */
496 Tester.prototype.assertTruthy = function assertTruthy(subject, message) {
497 "use strict";
498 /*jshint eqeqeq:false*/
499 return this.assert(utils.isTruthy(subject), message, {
500 type: "assertTruthy",
501 standard: "Subject is truthy",
502 values: {
503 subject: subject
504 }
505 });
506 };
507
508 /**
509 * Asserts a subject is falsy.
510 *
511 * @param Mixed subject Test subject
512 * @param String message Test description
513 * @return Object An assertion result object
514 */
515 Tester.prototype.assertFalsy = function assertFalsy(subject, message) {
516 "use strict";
517 /*jshint eqeqeq:false*/
518 return this.assert(utils.isFalsy(subject), message, {
519 type: "assertFalsy",
520 standard: "Subject is falsy",
521 values: {
522 subject: subject
523 }
524 });
525 };
526
527 /**
490 * Asserts that given text exists in the provided selector. 528 * Asserts that given text exists in the provided selector.
491 * 529 *
492 * @param String selector Selector expression 530 * @param String selector Selector expression
......
...@@ -287,6 +287,18 @@ function isClipRect(value) { ...@@ -287,6 +287,18 @@ function isClipRect(value) {
287 exports.isClipRect = isClipRect; 287 exports.isClipRect = isClipRect;
288 288
289 /** 289 /**
290 * Checks that the subject is falsy.
291 *
292 * @param Mixed subject Test subject
293 * @return Boolean
294 */
295 function isFalsy(subject) {
296 "use strict";
297 /*jshint eqeqeq:false*/
298 return subject == new Function('return false;')();
299 }
300 exports.isFalsy = isFalsy;
301 /**
290 * Checks if value is a javascript Function 302 * Checks if value is a javascript Function
291 * 303 *
292 * @param mixed value 304 * @param mixed value
...@@ -372,6 +384,19 @@ function isString(value) { ...@@ -372,6 +384,19 @@ function isString(value) {
372 exports.isString = isString; 384 exports.isString = isString;
373 385
374 /** 386 /**
387 * Checks that the subject is truthy.
388 *
389 * @param Mixed subject Test subject
390 * @return Boolean
391 */
392 function isTruthy(subject) {
393 "use strict";
394 /*jshint eqeqeq:false*/
395 return subject == new Function('return true;')();
396 }
397 exports.isTruthy = isTruthy;
398
399 /**
375 * Shorthands for checking if a value is of the given type. Can check for 400 * Shorthands for checking if a value is of the given type. Can check for
376 * arrays. 401 * arrays.
377 * 402 *
......
...@@ -43,6 +43,12 @@ casper.thenOpen('tests/site/index.html', function() { ...@@ -43,6 +43,12 @@ casper.thenOpen('tests/site/index.html', function() {
43 t.comment('Tester.assertTrue()'); 43 t.comment('Tester.assertTrue()');
44 t.assertTrue(true, 'Tester.assertTrue() works as expected [alias]'); 44 t.assertTrue(true, 'Tester.assertTrue() works as expected [alias]');
45 45
46 t.comment('Tester.assertTruthy()');
47 t.assertTruthy('1', 'Tester.assertTruthy() works as expected');
48
49 t.comment('Tester.assertFalsy()');
50 t.assertFalsy('0', 'Tester.assertFalsy() works as expected');
51
46 t.comment('Tester.assertNot()'); 52 t.comment('Tester.assertNot()');
47 t.assertNot(false, 'Tester.assertNot() works as expected'); 53 t.assertNot(false, 'Tester.assertNot() works as expected');
48 54
...@@ -205,5 +211,5 @@ casper.then(function() { ...@@ -205,5 +211,5 @@ casper.then(function() {
205 }); 211 });
206 212
207 casper.run(function() { 213 casper.run(function() {
208 t.done(56); 214 t.done(58);
209 }); 215 });
......