13

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

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
firefly
  • 131
  • 3

1 Answers1

17

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).

Rippo
  • 22,117
  • 14
  • 78
  • 117