Commit dce0aa77 dce0aa7730fa4c087b1f4ad72c14aaaade10ad85 by Nicolas Perriault

added Tester.assertTextDoesntExist()

1 parent b177ec84
...@@ -10,6 +10,7 @@ XXXX-XX-XX, v1.0.0 ...@@ -10,6 +10,7 @@ XXXX-XX-XX, v1.0.0
10 - fixed [#215](https://github.com/n1k0/casperjs/issues/215) - added a `--fail-fast` option to the `casper test` command, in order to terminate a test suite execution as soon as any failure is encountered 10 - fixed [#215](https://github.com/n1k0/casperjs/issues/215) - added a `--fail-fast` option to the `casper test` command, in order to terminate a test suite execution as soon as any failure is encountered
11 - fixed [#274](https://github.com/n1k0/casperjs/issues/274) - some headers couldn't be set 11 - fixed [#274](https://github.com/n1k0/casperjs/issues/274) - some headers couldn't be set
12 - fixed [#277](https://github.com/n1k0/casperjs/issues/277) - multiline support in `ClientUtils.echo()` 12 - fixed [#277](https://github.com/n1k0/casperjs/issues/277) - multiline support in `ClientUtils.echo()`
13 - added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist)
13 - added `Tester.assertFalse()` as an alias of `Tester.assertNot()` 14 - added `Tester.assertFalse()` as an alias of `Tester.assertNot()`
14 - added `page.resource.requested` and `page.resource.received` events 15 - added `page.resource.requested` and `page.resource.received` events
15 16
......
1 Subproject commit 2ad38f2ba8e89d6de6494bcfeed2dc76f256e283 1 Subproject commit efdaeb9e092054de1b30fa093ec2cd2435a2d894
......
...@@ -422,6 +422,27 @@ Tester.prototype.assertResourceExists = Tester.prototype.assertResourceExist = f ...@@ -422,6 +422,27 @@ Tester.prototype.assertResourceExists = Tester.prototype.assertResourceExist = f
422 }; 422 };
423 423
424 /** 424 /**
425 * Asserts that given text doesn't exist in the document body.
426 *
427 * @param String text Text not to be found
428 * @param String message Test description
429 * @return Object An assertion result object
430 */
431 Tester.prototype.assertTextDoesntExist = Tester.prototype.assertTextDoesntExist = function assertTextDoesntExist(text, message) {
432 "use strict";
433 var textFound = (this.casper.evaluate(function _evaluate() {
434 return document.body.textContent || document.body.innerText;
435 }).indexOf(text) === -1);
436 return this.assert(textFound, message, {
437 type: "assertTextDoesntExists",
438 standard: "Text doesn't exist within the document body",
439 values: {
440 text: text
441 }
442 });
443 };
444
445 /**
425 * Asserts that given text exists in the document body. 446 * Asserts that given text exists in the document body.
426 * 447 *
427 * @param String text Text to be found 448 * @param String text Text to be found
...@@ -450,11 +471,11 @@ Tester.prototype.assertTextExists = Tester.prototype.assertTextExist = function ...@@ -450,11 +471,11 @@ Tester.prototype.assertTextExists = Tester.prototype.assertTextExist = function
450 * @param String message Test description 471 * @param String message Test description
451 * @return Object An assertion result object 472 * @return Object An assertion result object
452 */ 473 */
453 Tester.prototype.assertSelectorHasText = function assertSelectorHasText(selector, text, message) { 474 Tester.prototype.assertSelectorHasText = Tester.prototype.assertSelectorContains = function assertSelectorHasText(selector, text, message) {
454 "use strict"; 475 "use strict";
455 var textFound = this.casper.fetchText(selector).indexOf(text) !== -1; 476 var textFound = this.casper.fetchText(selector).indexOf(text) !== -1;
456 return this.assert(textFound, message, { 477 return this.assert(textFound, message, {
457 type: "assertTextInSelector", 478 type: "assertSelectorHasText",
458 standard: f('Found "%s" within the selector "%s"', text, selector), 479 standard: f('Found "%s" within the selector "%s"', text, selector),
459 values: { 480 values: {
460 selector: selector, 481 selector: selector,
...@@ -471,11 +492,11 @@ Tester.prototype.assertSelectorHasText = function assertSelectorHasText(selector ...@@ -471,11 +492,11 @@ Tester.prototype.assertSelectorHasText = function assertSelectorHasText(selector
471 * @param String message Test description 492 * @param String message Test description
472 * @return Object An assertion result object 493 * @return Object An assertion result object
473 */ 494 */
474 Tester.prototype.assertSelectorDoesntHaveText = function assertSelectorDoesntHaveText(selector, text, message) { 495 Tester.prototype.assertSelectorDoesntHaveText = Tester.prototype.assertSelectorDoesntContain = function assertSelectorDoesntHaveText(selector, text, message) {
475 "use strict"; 496 "use strict";
476 var textFound = this.casper.fetchText(selector).indexOf(text) === -1; 497 var textFound = this.casper.fetchText(selector).indexOf(text) === -1;
477 return this.assert(textFound, message, { 498 return this.assert(textFound, message, {
478 type: "assertNoTextInSelector", 499 type: "assertSelectorDoesntHaveText",
479 standard: f('Did not find "%s" within the selector "%s"', text, selector), 500 standard: f('Did not find "%s" within the selector "%s"', text, selector),
480 values: { 501 values: {
481 selector: selector, 502 selector: selector,
......
...@@ -28,6 +28,9 @@ casper.thenOpen('tests/site/index.html', function() { ...@@ -28,6 +28,9 @@ casper.thenOpen('tests/site/index.html', function() {
28 t.comment('Tester.assertTextExist()'); 28 t.comment('Tester.assertTextExist()');
29 t.assertTextExist('form', 'Tester.assertTextExist() checks that page body contains text [alias]'); 29 t.assertTextExist('form', 'Tester.assertTextExist() checks that page body contains text [alias]');
30 30
31 t.comment('Tester.assertTextDoesntExist()');
32 t.assertTextDoesntExist('blah', "Tester.assertTextDoesntExist() checks that page body doesn't contain provided text");
33
31 t.comment('Tester.assertSelectorHasText()'); 34 t.comment('Tester.assertSelectorHasText()');
32 t.assertSelectorHasText('h1', 'Title', 'Tester.assertSelectorHasText() works as expected'); 35 t.assertSelectorHasText('h1', 'Title', 'Tester.assertSelectorHasText() works as expected');
33 36
......