-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
87 lines (70 loc) · 1.82 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
85
86
87
var test = require('tape')
var nanotick = require('./')
test('nanotick', function (t) {
t.test('should assert input types', function (t) {
t.plan(1)
var tick = nanotick()
t.throws(tick.bind(null), /function/)
})
t.test('async functions should resolve in the same tick', function (t) {
t.plan(1)
var oops = false
process.nextTick(function () {
process.nextTick(function () {
oops = true
})
})
var tick = nanotick()
var fn = tick(function () {
t.equal(oops, false)
})
process.nextTick(fn)
})
t.test('sync function should resolve in the next tick', function (t) {
t.plan(1)
var oops = false
process.nextTick(function () {
process.nextTick(function () {
oops = true
})
})
var tick = nanotick()
var fn = tick(function () {
t.equal(oops, false)
})
fn()
})
t.test('is able to push more values onto the same tick from within a tick', function (t) {
t.plan(2)
var changed = false
process.nextTick(function () {
process.nextTick(function () {
changed = true
})
})
var tick = nanotick()
;(tick(function () {
t.equal(changed, false)
;(tick(function () {
t.equal(changed, false)
}))()
}))()
})
t.test('scheduled functions should be cleared after their execution', function (t) {
t.plan(1)
var numCalls = 0
var tick = nanotick()
// Arrange for a function to be called on the first tick
tick(function () {
++numCalls
})()
process.nextTick(function () {
// Arrange for another function to be called on the second tick
tick(function () {
})()
process.nextTick(function () {
t.equal(numCalls, 1, 'There should only be one call to a scheduled function')
})
})
})
})