after-test.js
2.1 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*global suite, test*/
var assert = require("assert")
, after = require("../")
test("exists", function () {
assert(typeof after === "function", "after is not a function")
})
test("after when called with 0 invokes", function (done) {
after(0, done)
});
test("after 1", function (done) {
var next = after(1, done)
next()
})
test("after 5", function (done) {
var next = after(5, done)
, i = 5
while (i--) {
next()
}
})
test("manipulate count", function (done) {
var next = after(1, done)
, i = 5
next.count = i
while (i--) {
next()
}
})
test("after terminates on error", function (done) {
var next = after(2, function(err) {
assert.equal(err.message, 'test');
done();
})
next(new Error('test'))
next(new Error('test2'))
})
test('gee', function(done) {
done = after(2, done)
function cb(err) {
assert.equal(err.message, 1);
done()
}
var next = after(3, cb, function(err) {
assert.equal(err.message, 2)
done()
});
next()
next(new Error(1))
next(new Error(2))
})
test('eee', function(done) {
done = after(3, done)
function cb(err) {
assert.equal(err.message, 1);
done()
}
var next = after(3, cb, function(err) {
assert.equal(err.message, 2)
done()
});
next(new Error(1))
next(new Error(2))
next(new Error(2))
})
test('gge', function(done) {
function cb(err) {
assert.equal(err.message, 1);
done()
}
var next = after(3, cb, function(err) {
// should not happen
assert.ok(false);
});
next()
next()
next(new Error(1))
})
test('egg', function(done) {
function cb(err) {
assert.equal(err.message, 1);
done()
}
var next = after(3, cb, function(err) {
// should not happen
assert.ok(false);
});
next(new Error(1))
next()
next()
})
test('throws on too many calls', function(done) {
var next = after(1, done);
next()
assert.throws(next, /after called too many times/);
});