Skip to content

Commit e8255cf

Browse files
committed
[Tests] add timeoutAfter test with Promises
1 parent df5a124 commit e8255cf

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/timeoutAfter.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,64 @@ tap.test('timeoutAfter test', function (tt) {
3636
t.timeoutAfter(1);
3737
});
3838
});
39+
40+
tap.test('timeoutAfter with Promises', function (tt) {
41+
tt.plan(1);
42+
43+
var test = tape.createHarness();
44+
var tc = function (rows) {
45+
tt.same(stripFullStack(rows.toString('utf8')), [
46+
'TAP version 13',
47+
'# timeoutAfter with promises',
48+
'# fulfilled promise',
49+
'not ok 1 fulfilled promise timed out after 1ms',
50+
' ---',
51+
' operator: fail',
52+
' stack: |-',
53+
' Error: fulfilled promise timed out after 1ms',
54+
' [... stack stripped ...]',
55+
' ...',
56+
'# rejected promise',
57+
'not ok 2 rejected promise timed out after 1ms',
58+
' ---',
59+
' operator: fail',
60+
' stack: |-',
61+
' Error: rejected promise timed out after 1ms',
62+
' [... stack stripped ...]',
63+
' ...',
64+
'',
65+
'1..2',
66+
'# tests 2',
67+
'# pass 0',
68+
'# fail 2'
69+
].join('\n') + '\n');
70+
};
71+
72+
test.createStream().pipe(concat(tc));
73+
74+
test('timeoutAfter with promises', function (t) {
75+
t.plan(2);
76+
77+
t.test('fulfilled promise', function (st) {
78+
st.plan(1);
79+
st.timeoutAfter(1);
80+
81+
return new Promise(function (resolve) {
82+
setTimeout(function () {
83+
resolve();
84+
}, 2);
85+
});
86+
});
87+
88+
t.test('rejected promise', function (st) {
89+
st.plan(1);
90+
st.timeoutAfter(1);
91+
92+
return new Promise(function (reject) {
93+
setTimeout(function () {
94+
reject();
95+
}, 2);
96+
});
97+
});
98+
});
99+
});

0 commit comments

Comments
 (0)