Skip to content

Commit 1dc4551

Browse files
committed
Add some tests regarding async assertions and t.plan
1 parent 8b4fc5a commit 1dc4551

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,34 @@ test('test returns a promise that resolves before a promise passed to t.throws r
428428
t.end();
429429
});
430430
});
431+
432+
test('multiple resolving and rejecting promises passed to t.throws/t.doesNotThrow', function (t) {
433+
ava(function (a) {
434+
a.plan(6);
435+
for (var i = 0; i < 3; ++i) {
436+
a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo');
437+
a.doesNotThrow(delay(Promise.resolve(), 10), 'foo');
438+
}
439+
}).run().then(function (a) {
440+
t.ifError(a.assertError);
441+
t.is(a.planCount, 6);
442+
t.is(a.assertCount, 6);
443+
t.end();
444+
});
445+
});
446+
447+
test('number of assertions matches t.plan when the test exits, but before all promises resolve another is added', function (t) {
448+
ava(function (a) {
449+
a.plan(2);
450+
a.throws(delay(Promise.reject(new Error('foo')), 10), 'foo');
451+
a.doesNotThrow(delay(Promise.resolve(), 10), 'foo');
452+
setTimeout(function () {
453+
a.throws(Promise.reject(new Error('foo')), 'foo');
454+
}, 5);
455+
}).run().catch(function(err) {
456+
t.is(err.operator, 'plan');
457+
t.is(err.actual, 3);
458+
t.is(err.expected, 2);
459+
t.end();
460+
})
461+
});

0 commit comments

Comments
 (0)