/
test.js
62 lines (49 loc) · 1.16 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
var test = require('tape');
var wait = require('./tmpvar-future-wait');
var future = require('tmpvar-future');
test('resolves immediately when passed primitives', function(t) {
var f = wait(1, 'a', false, null, [], {}, function noop() {}, function(err, args) {
t.equal(args[0], 1);
t.equal(args[1], 'a');
t.equal(args[2], false);
t.equal(args[3], null);
t.deepEqual(args[4], []);
t.deepEqual(args[5], {});
t.equal(typeof args[6], 'function');
t.end();
});
});
test('returns a future', function(t) {
var f = wait(1);
f(function(e, a) {
t.equal(a[0], 1);
t.ok(!e);
t.end();
});
});
test('waits for all futures', function(t) {
var f1 = future();
var f2 = future();
wait(f1, f2, function(err, args) {
t.equal(args[0], 1);
t.equal(args[1], 2)
t.end();
});
process.nextTick(function() {
f1(null, 1);
});
f2(null, 2);
});
test('handle array and callback', function(t) {
var f1 = future();
var f2 = future();
wait([f1, f2], function(err, args) {
t.equal(args[0], 1);
t.equal(args[1], 2)
t.end();
});
process.nextTick(function() {
f1(null, 1);
});
f2(null, 2);
});