-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.js
46 lines (36 loc) · 949 Bytes
/
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
import test from 'ava'
import { requestAnimationFrame, cancelAnimationFrame } from './src/index.js'
import raf from 'raf'
raf.polyfill()
test.cb('only invoke once', t => {
let count = 0
const add = () => count += 1
requestAnimationFrame(add)
requestAnimationFrame(add)
requestAnimationFrame(add)
setTimeout(() => {
t.is(count, 1)
t.end()
}, 20)
})
test.cb('return same id for duplicate callback', t => {
const animation = () => { }
const id1 = requestAnimationFrame(animation)
const id2 = requestAnimationFrame(animation)
setTimeout(() => {
t.is(id1, id2)
t.end()
}, 20)
})
test.cb('cancel', t => {
let count = 0
const add = () => count += 1
requestAnimationFrame(add)
requestAnimationFrame(add)
const id = requestAnimationFrame(add)
cancelAnimationFrame(id)
setTimeout(() => {
t.is(count, 0)
t.end()
}, 20)
})