forked from canjs/canjs
/
modifier_test.js
69 lines (55 loc) · 1.49 KB
/
modifier_test.js
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
steal('can/util', 'can/control/modifier', function(can) {
module("can/control/modifier");
asyncTest("pluginName", function() {
var controllerClass = can.Control({
}, {
" click:debounce(30)" : function() {
ok( this instanceof can.Control, "Debounced function has the correct context." );
foo = true;
run++;
},
"bar:debounce(30)" : function() {
run2++;
}
});
/**/
var controller1 = new controllerClass( $("#foo") ),
controller2 = new controllerClass( $("#bar") ),
run = 0,
run2 = 0,
foo;
// Do a bunch of clicks!
$("#foo").trigger("click");
$("#bar").trigger("click");
$("#foo").trigger("click");
$("#bar").trigger("click");
$("#foo").trigger("click");
$("#bar").trigger("click");
// Make sure foo is still undefined (should be > 30ms before its defined)
ok( ! foo, "`foo` is undefined." );
console.dir( controller1 );
ok( "bar" in controller1, "Method name gets aliased correctly");
controller1.bar();
controller1.bar();
controller1.bar();
controller1.bar();
// Check if
setTimeout(function() {
ok( foo, "`foo` is true." );
equals( run, 2, "`run` is 2" );
equals( run2, 1, "`run2` is 1" );
// Do a bunch more clicks!
$("#foo").trigger("click");
$("#bar").trigger("click");
$("#foo").trigger("click");
$("#bar").trigger("click");
$("#foo").trigger("click");
$("#bar").trigger("click");
setTimeout(function() {
ok( run === 4, "`run` is 4" );
start();
}, 40);
}, 40);
/**/
});
});