steps.js
1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*eslint strict:0*/
casper.test.begin('steps tests', 8, function(test) {
casper.start('tests/site/index.html');
var nsteps = casper.steps.length;
casper.then(function(response) {
test.assertTitle('CasperJS test index',
'Casper.then() added a new step');
});
test.assertEquals(casper.steps.length, nsteps + 1,
'Casper.then() can add a new step');
casper.thenOpen('tests/site/test.html');
test.assertEquals(casper.steps.length, nsteps + 2,
'Casper.thenOpen() can add a new step');
casper.thenOpen('tests/site/test.html', function() {
test.assertTitle('CasperJS test target',
'Casper.thenOpen() opened a location and executed a step');
});
test.assertEquals(casper.steps.length, nsteps + 4,
'Casper.thenOpen() can add a new step for opening, plus another step');
casper.each([1, 2, 3], function(self, item, i) {
test.assertEquals(i, item - 1,
'Casper.each() passes a contextualized index');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('eachThen() tests', 2, function(test) {
var received = [];
var receivedFalsy = [];
casper.start().eachThen([1, 2, 3], function(response) {
if (!response) {
test.fail('No response received');
}
received.push(response.data);
});
casper.then(function() {
test.assertEquals(received, [1, 2, 3],
'Casper.eachThen() passes item to step data');
});
casper.eachThen([false, 0, ''], function(response) {
if (!response) {
test.fail('No response received');
}
receivedFalsy.push(response.data);
});
casper.then(function() {
test.assertEquals(receivedFalsy, [false, 0, ''],
'Casper.eachThen() passes falsy items to step data');
});
casper.run(function() {
test.done();
});
});