-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
84 lines (63 loc) · 1.3 KB
/
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import test from 'tape';
import onFrame from './index';
test('debounces after 10 frames', function(t) {
t.plan(1);
let called = 0;
let ticked = 0;
function count() {
called++;
}
const func = onFrame(count);
setTimeout(function tick() {
requestAnimationFrame(func);
ticked++;
if (ticked < 10) {
setTimeout(tick, 50);
} else {
setTimeout(function() {
t.equal(called, 1);
}, 600);
}
}, 50);
});
test('debounces after 1 frame', function(t) {
t.plan(1);
let called = 0;
let ticked = 0;
function count() {
called++;
}
const func = onFrame(count, 1);
setTimeout(function tick() {
requestAnimationFrame(func);
ticked++;
if (ticked < 10) {
setTimeout(tick, 50);
} else {
setTimeout(function() {
t.equal(called, 10);
}, 600);
}
}, 50);
});
test('cancels callback', function(t) {
t.plan(1);
let called = 0;
let ticked = 0;
const func = onFrame(count, 10);
function count() {
called++;
}
setTimeout(function tick() {
requestAnimationFrame(func);
ticked++;
if (ticked < 10) {
setTimeout(tick, 50);
} else {
setTimeout(func.cancel.bind(func), 100);
setTimeout(function() {
t.equal(called, 0);
}, 600);
}
}, 50);
});