Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "test.begin()" function mean in CasperJS?

I don't quite understand the function test.begin(String description, Number planned, Function suite). What is the parameter Number planed for?

like image 504
firefly Avatar asked Nov 15 '14 06:11

firefly


1 Answers

Number planned is the number of asserts that you expect to test. This is totally optional and can be thought about as a a sanity check that your test script has actually completed fully.

The docs states:-

The planned argument is especially useful in case a given test script is abruptly interrupted leaving you with no obvious way to know it and an erroneously successful status.

An example:-

casper.test.begin('when testing foo', 3, function() {
    test.assertEquals(1 === 1, '1 equals 1');
    test.assertEquals(5 === 5, '5 equals 5');
    test.done();
});

This test would actually fail as I have defined 3 planned asserts but only 2 have succeeded (as there are only 2 asserts).

like image 60
Rippo Avatar answered Sep 22 '22 15:09

Rippo