events.js
1.38 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
/*eslint strict:0*/
casper.test.begin('events', 2, function(test) {
casper.plopped = false;
casper.once("plop", function() {
this.plopped = true;
});
test.assert(Object.keys(casper._events).some(function(i) {
return i === "plop";
}), "on() has set an event handler");
casper.emit("plop");
test.assert(casper.plopped, "emit() emits an event");
test.done();
});
casper.test.begin('filters', 3, function(test) {
casper.foo = 0;
casper.setFilter("test", function(a) {
this.foo = 42;
return a + 1;
});
test.assert(Object.keys(casper._filters).some(function(i) {
return i === "test";
}), "setFilter() has set a filter");
test.assertEquals(casper.filter("test", 1), 2, "filter() filters a value");
test.assertEquals(casper.foo, 42, "filter() applies the correct context");
delete casper.foo;
test.done();
});
casper.test.begin('events order', 2, function(test) {
casper.mowed = "Moo";
casper.on("mow", function() {
this.mowed = casper.mowed + " Moo";
});
casper.emit("mow");
test.assertEquals(casper.mowed, "Moo Moo", "mowed has the correct value");
casper.prependListener("mow", function() {
this.mowed = this.mowed + " Boo";
});
casper.emit("mow");
test.assertEquals(casper.mowed, "Moo Moo Boo Moo", "mowed has the correct value");
test.done();
});