-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
75 lines (63 loc) · 1.63 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
var waitress = require('./index')
, assert = require('assert');
describe('waitress', function() {
it('should recieve an error', function() {
assert.throws(function() {
var done = waitress(3, function(err) {
if (err) throw err;
});
done();
done();
done(new Error);
});
});
it('should receive error from single callback', function() {
assert.throws(function() {
var done = waitress(1, function(err) {
if (err) throw err;
});
done(new Error('hai tai mai shu'));
}, /hai tai mai shu/);
});
it('should execute cb with zero count', function(next) {
// for zero args
var done = waitress(0, function(err, arr) {
assert.ok(!err);
assert.deepEqual(arr, []);
next();
});
});
it('should ignore false error param', function() {
assert.doesNotThrow(function() {
var done = waitress(3, function(err) {
if (err) throw err;
});
done();
done();
done();
done(false);
});
});
it('should return last error', function() {
assert.throws(function() {
var done = waitress(3, function(err, results) {
if (err) throw err;
});
done();
done(new Error("nein nein nein"));
done(new Error("no no no"));
}, /no no no/);
});
it('should aggregate results', function() {
(function() {
var done = waitress(3, function(err, results) {
if (err) throw err;
assert.deepEqual(results, [1, 2, 3], "results aggregation wrong");
});
done(null, 1);
done(null, 2);
done(null, 3);
done(null, 4);
})();
});
});