Commit dce0aa77 dce0aa7730fa4c087b1f4ad72c14aaaade10ad85 by Nicolas Perriault

added Tester.assertTextDoesntExist()

1 parent b177ec84
......@@ -10,6 +10,7 @@ XXXX-XX-XX, v1.0.0
- 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
- fixed [#274](https://github.com/n1k0/casperjs/issues/274) - some headers couldn't be set
- fixed [#277](https://github.com/n1k0/casperjs/issues/277) - multiline support in `ClientUtils.echo()`
- added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist)
- added `Tester.assertFalse()` as an alias of `Tester.assertNot()`
- added `page.resource.requested` and `page.resource.received` events
......
Subproject commit 2ad38f2ba8e89d6de6494bcfeed2dc76f256e283
Subproject commit efdaeb9e092054de1b30fa093ec2cd2435a2d894
......
......@@ -422,6 +422,27 @@ Tester.prototype.assertResourceExists = Tester.prototype.assertResourceExist = f
};
/**
* Asserts that given text doesn't exist in the document body.
*
* @param String text Text not to be found
* @param String message Test description
* @return Object An assertion result object
*/
Tester.prototype.assertTextDoesntExist = Tester.prototype.assertTextDoesntExist = function assertTextDoesntExist(text, message) {
"use strict";
var textFound = (this.casper.evaluate(function _evaluate() {
return document.body.textContent || document.body.innerText;
}).indexOf(text) === -1);
return this.assert(textFound, message, {
type: "assertTextDoesntExists",
standard: "Text doesn't exist within the document body",
values: {
text: text
}
});
};
/**
* Asserts that given text exists in the document body.
*
* @param String text Text to be found
......@@ -450,11 +471,11 @@ Tester.prototype.assertTextExists = Tester.prototype.assertTextExist = function
* @param String message Test description
* @return Object An assertion result object
*/
Tester.prototype.assertSelectorHasText = function assertSelectorHasText(selector, text, message) {
Tester.prototype.assertSelectorHasText = Tester.prototype.assertSelectorContains = function assertSelectorHasText(selector, text, message) {
"use strict";
var textFound = this.casper.fetchText(selector).indexOf(text) !== -1;
return this.assert(textFound, message, {
type: "assertTextInSelector",
type: "assertSelectorHasText",
standard: f('Found "%s" within the selector "%s"', text, selector),
values: {
selector: selector,
......@@ -471,11 +492,11 @@ Tester.prototype.assertSelectorHasText = function assertSelectorHasText(selector
* @param String message Test description
* @return Object An assertion result object
*/
Tester.prototype.assertSelectorDoesntHaveText = function assertSelectorDoesntHaveText(selector, text, message) {
Tester.prototype.assertSelectorDoesntHaveText = Tester.prototype.assertSelectorDoesntContain = function assertSelectorDoesntHaveText(selector, text, message) {
"use strict";
var textFound = this.casper.fetchText(selector).indexOf(text) === -1;
return this.assert(textFound, message, {
type: "assertNoTextInSelector",
type: "assertSelectorDoesntHaveText",
standard: f('Did not find "%s" within the selector "%s"', text, selector),
values: {
selector: selector,
......
......@@ -28,6 +28,9 @@ casper.thenOpen('tests/site/index.html', function() {
t.comment('Tester.assertTextExist()');
t.assertTextExist('form', 'Tester.assertTextExist() checks that page body contains text [alias]');
t.comment('Tester.assertTextDoesntExist()');
t.assertTextDoesntExist('blah', "Tester.assertTextDoesntExist() checks that page body doesn't contain provided text");
t.comment('Tester.assertSelectorHasText()');
t.assertSelectorHasText('h1', 'Title', 'Tester.assertSelectorHasText() works as expected');
......