-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
90 lines (68 loc) · 1.41 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
88
89
90
'use strict';
var test = require('tape');
var wait = require('./wait-for-it');
test('wait is an object', function(t) {
t.plan(1);
t.equal('object', typeof wait);
});
test('basic push', function(t) {
t.plan(1);
wait.setup(function(data) {
t.equal(data[0], 'something');
}, 1000);
wait.push('something');
});
test('callback only called once', function(t) {
t.plan(1);
wait.setup(function() {
t.pass();
}, 1000);
wait.push('1');
wait.push('2');
wait.push('3');
});
test('data matches what is queued', function(t) {
t.plan(1);
wait.setup(function(data) {
t.equal(data.length, 3);
}, 1000);
wait.push('1');
wait.push('2');
wait.push('3');
});
test('callback is fired multiple times', function(t) {
t.plan(2);
wait.setup(function() {
t.pass();
}, 1000);
wait.push('1');
setTimeout(function() {
wait.push('2');
}, 3000);
});
test('multiple queues', function(t) {
t.plan(2);
var q1 = Object.create(wait);
q1.setup(function(data) {
t.equal(data[0], 'q1');
}, 1000);
var q2 = Object.create(wait);
q2.setup(function(data) {
t.equal(data[0], 'q2');
}, 1000);
q1.push('q1');
q2.push('q2');
});
test('this context set via callback', function(t) {
t.plan(1);
var fixture = {
fn: function() {
this.success();
},
success: function() {
t.pass();
}
};
wait.setup(fixture.fn, 1000, fixture);
wait.push('1');
});