Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit eb111c8

Browse files
committed
revamped tester examples with more accurate snippets
1 parent 7fd804a commit eb111c8

File tree

1 file changed

+94
-32
lines changed

1 file changed

+94
-32
lines changed

modules/tester.rst

Lines changed: 94 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,13 @@ Asserts that a given subject is `falsy <http://11heavens.com/falsy-and-truthy-in
164164

165165
Asserts that a given form field has the provided value::
166166

167-
casper.start('http://www.google.fr/', function() {
168-
this.fill('form[name="gs"]', { q: 'plop' }, false);
169-
this.test.assertField('q', 'plop');
167+
casper.test.begin('assertField() tests', 1, function(test) {
168+
casper.start('http://www.google.fr/', function() {
169+
this.fill('form[name="gs"]', { q: 'plop' }, false);
170+
test.assertField('q', 'plop');
171+
}).run(function() {
172+
test.done();
173+
});
170174
});
171175

172176
.. versionadded:: 1.0
@@ -182,8 +186,12 @@ This also works with any input type: ``select``, ``textarea``, etc.
182186

183187
Asserts that current `HTTP status code <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>`_ is the same as the one passed as argument::
184188

185-
casper.start('http://www.google.fr/', function() {
186-
this.test.assertHttpStatus(200, 'google.fr is up');
189+
casper.test.begin('casperjs.org is up and running', 1, function(test) {
190+
casper.start('http://casperjs.org/', function() {
191+
test.assertHttpStatus(200);
192+
}).run(function() {
193+
test.done();
194+
});
187195
});
188196

189197
``assertMatch()``
@@ -220,7 +228,7 @@ Asserts that the passed subject resolves to some `falsy value <http://11heavens.
220228

221229
Asserts that two values are **not** strictly equals::
222230

223-
casper.test.assertNotEquals(true, "Truth is out");
231+
casper.test.assertNotEquals(true, "true");
224232

225233
.. seealso:: `assertEquals()`_
226234

@@ -231,8 +239,13 @@ Asserts that two values are **not** strictly equals::
231239

232240
Asserts that the element matching the provided :ref:`selector expression <selectors>` is not visible::
233241

234-
casper.start('http://www.google.fr/', function() {
235-
this.test.assertNotVisible('h6');
242+
casper.test.begin('assertNotVisible() tests', 1, function(test) {
243+
casper.start().then(function() {
244+
this.setContent('<div class=".foo" style="display:none>boo</div>');
245+
test.assertNotVisible('.foo');
246+
}).run(function() {
247+
test.done();
248+
});
236249
});
237250

238251
.. seealso:: `assertVisible()`_
@@ -265,8 +278,12 @@ Asserts that the provided function called with the given parameters raises a jav
265278

266279
Asserts that given text does not exist in all the elements matching the provided :ref:`selector expression <selectors>`::
267280

268-
casper.start('http://www.google.fr/', function() {
269-
this.test.assertSelectorDoesntHaveText('title', 'Yahoo!');
281+
casper.test.begin('assertSelectorDoesntHaveText() tests', 1, function(test) {
282+
casper.start('http://google.com/', function() {
283+
test.assertSelectorDoesntHaveText('title', 'Yahoo!');
284+
}).run(function() {
285+
test.done();
286+
});
270287
});
271288

272289
.. seealso:: `assertSelectorHasText()`_
@@ -280,8 +297,12 @@ Asserts that given text does not exist in all the elements matching the provided
280297

281298
Asserts that given text exists in elements matching the provided :ref:`selector expression <selectors>`::
282299

283-
casper.start('http://www.google.fr/', function() {
284-
this.test.assertSelectorHasText('title', 'Google');
300+
casper.test.begin('assertSelectorHasText() tests', 1, function(test) {
301+
casper.start('http://google.com/', function() {
302+
test.assertSelectorDoesntHaveText('title', 'Google');
303+
}).run(function() {
304+
test.done();
305+
});
285306
});
286307

287308
.. seealso:: `assertSelectorDoesntHaveText()`_
@@ -295,12 +316,24 @@ Asserts that given text exists in elements matching the provided :ref:`selector
295316

296317
The ``testFx`` function is executed against all loaded assets and the test passes when at least one resource matches::
297318

298-
casper.start('http://www.google.fr/', function() {
299-
this.test.assertResourceExists(function (resource) {
300-
return resource.url.match('logo3w.png');
301-
}, 'google.fr logo was loaded');
302-
// or shorter
303-
this.test.assertResourceExists('logo3w.png', 'google.fr logo was loaded');
319+
casper.test.begin('assertResourceExists() tests', 1, function(test) {
320+
casper.start('http://www.google.fr/', function() {
321+
test.assertResourceExists(function(resource) {
322+
return resource.url.match('logo3w.png');
323+
});
324+
}).run(function() {
325+
test.done();
326+
});
327+
});
328+
329+
Shorter::
330+
331+
casper.test.begin('assertResourceExists() tests', 1, function(test) {
332+
casper.start('http://www.google.fr/', function() {
333+
test.assertResourceExists('logo3w.png');
334+
}).run(function() {
335+
test.done();
336+
});
304337
});
305338

306339
.. hint::
@@ -314,8 +347,12 @@ The ``testFx`` function is executed against all loaded assets and the test passe
314347

315348
Asserts that body **plain text content** contains the given string::
316349

317-
casper.start('http://www.google.fr/', function() {
318-
this.test.assertTextExists('google', 'page body contains "google"');
350+
casper.test.begin('assertTextExists() tests', 1, function(test) {
351+
casper.start('http://www.google.fr/', function() {
352+
test.assertTextExists('google', 'page body contains "google"');
353+
}).run(function() {
354+
test.done();
355+
});
319356
});
320357

321358
.. seealso:: `assertTextDoesntExist()`_
@@ -329,8 +366,12 @@ Asserts that body **plain text content** contains the given string::
329366

330367
Asserts that body **plain text content** doesn't contain the given string::
331368

332-
casper.start('http://www.google.fr/', function() {
333-
this.test.assertTextDoesntExist('bing', 'page body does not contain "bing"');
369+
casper.test.begin('assertTextDoesntExist() tests', 1, function(test) {
370+
casper.start('http://www.google.fr/', function() {
371+
test.assertTextDoesntExist('bing', 'page body does not contain "bing"');
372+
}).run(function() {
373+
test.done();
374+
});
334375
});
335376

336377
.. seealso:: `assertTextExists()`_
@@ -342,8 +383,12 @@ Asserts that body **plain text content** doesn't contain the given string::
342383

343384
Asserts that title of the remote page equals to the expected one::
344385

345-
casper.start('http://www.google.fr/', function() {
346-
this.test.assertTitle('Google', 'google.fr has the correct title');
386+
casper.test.begin('assertTitle() tests', 1, function(test) {
387+
casper.start('http://www.google.fr/', function() {
388+
test.assertTitle('Google', 'google.fr has the correct title');
389+
}).run(function() {
390+
test.done();
391+
});
347392
});
348393

349394
.. seealso:: `assertTitleMatch()`_
@@ -355,8 +400,12 @@ Asserts that title of the remote page equals to the expected one::
355400

356401
Asserts that title of the remote page matches the provided RegExp pattern::
357402

358-
casper.start('http://www.google.fr/', function() {
359-
this.test.assertTitleMatch(/Google/, 'google.fr has a quite predictable title');
403+
casper.test.begin('assertTitleMatch() tests', 1, function(test) {
404+
casper.start('http://www.google.fr/', function() {
405+
test.assertTitleMatch(/Google/, 'google.fr has a quite predictable title');
406+
}).run(function() {
407+
test.done();
408+
});
360409
});
361410

362411
.. seealso:: `assertTitle()`_
@@ -383,8 +432,13 @@ Asserts that a given subject is `truthy <http://11heavens.com/falsy-and-truthy-i
383432

384433
Asserts that the provided input is of the given type::
385434

386-
casper.test.assertType(42, "number", "Okay, 42 is a number");
387-
casper.test.assertType([1, 2, 3], "array", "Yeah, we can test for arrays too =)");
435+
casper.test.begin('assertType() tests', 1, function suite(test) {
436+
test.assertType(42, "number", "Okay, 42 is a number");
437+
test.assertType([1, 2, 3], "array", "We can test for arrays too!");
438+
test.done();
439+
});
440+
441+
.. note:: Type names are always expressed in lower case.
388442

389443
.. index:: URL
390444

@@ -395,8 +449,12 @@ Asserts that the provided input is of the given type::
395449

396450
Asserts that a the current page url matches the provided RegExp pattern::
397451

398-
casper.start('http://www.google.fr/', function() {
399-
this.test.assertUrlMatch(/^http:\/\//', 'google.fr is served in http://');
452+
casper.test.begin('assertUrlMatch() tests', 1, function(test) {
453+
casper.start('http://www.google.fr/', function() {
454+
test.assertUrlMatch(/^http:\/\//', 'google.fr is served in http://');
455+
}).run(function() {
456+
test.done();
457+
});
400458
});
401459

402460
.. index:: DOM
@@ -408,8 +466,12 @@ Asserts that a the current page url matches the provided RegExp pattern::
408466

409467
Asserts that the element matching the provided :ref:`selector expression <selectors>` is visible::
410468

411-
casper.start('http://www.google.fr/', function() {
412-
this.test.assertVisible('h1');
469+
casper.test.begin('assertVisible() tests', 1, function(test) {
470+
casper.start('http://www.google.fr/', function() {
471+
test.assertVisible('h1');
472+
}).run(function() {
473+
test.done();
474+
});
413475
});
414476

415477
.. seealso:: `assertNotVisible()`_

0 commit comments

Comments
 (0)