UNPKG

1.21 kBJavaScriptView Raw
1var test = require('tape')
2 , raf = require('./index')
3
4test('continues to emit events', function(t) {
5 var canvas = typeof document === "undefined" ? {} : document.createElement('canvas')
6 , ee = raf(canvas)
7 , times = 0
8
9 t.plan(10)
10
11 canvas.width = canvas.height = 100
12
13 ee
14 .on('data', function(dt) {
15 t.ok(dt >= 0, "time has passed")
16 if(++times == 10) {
17 ee.pause()
18 t.end()
19 }
20 })
21})
22
23test('default tick function gets data', function(t) {
24 var canvas = typeof document === "undefined" ? {} : document.createElement('canvas')
25 , ee = raf(canvas, function tick(dt) {
26 t.true(!!dt, 'got data') // got data!
27 ee.pause()
28 t.end()
29 })
30})
31
32test('pause/resume', function(t) {
33 t.plan(7)
34 var canvas = typeof document === 'undefined' ? {} : document.createElement('canvas')
35 , times = 0
36 , ee = raf(canvas, function tick(dt) {
37 times++
38 t.ok(dt >= 0, 'time has passed')
39 if(times == 5) {
40 ee.pause()
41 setTimeout(function() {
42 ee.resume()
43 }, 100)
44 }
45 if(times == 6) {
46 t.ok(dt >= 100, 'stream resumed after pause')
47 ee.pause()
48 t.end()
49 }
50 })
51})
52