Skip to content

Commit 3146d33

Browse files
committed
Fix t.plan when the number of assertions is incorrect when the test exits, but is correct once all assertions have resolved
1 parent 7ffc043 commit 3146d33

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lib/test.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,23 @@ Test.prototype._end = function (err) {
172172
Test.prototype.exit = function () {
173173
var self = this;
174174

175+
function checkAssertLength() {
176+
if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertPromises.length) {
177+
self._setAssertError(new assert.AssertionError({
178+
actual: self.assertPromises.length,
179+
expected: self.planCount,
180+
message: 'Assertion count does not match planned',
181+
operator: 'plan'
182+
}));
183+
184+
self.assertError.stack = self.planStack;
185+
return false;
186+
}
187+
return true;
188+
}
189+
190+
checkAssertLength();
191+
175192
Promise.all(this.assertPromises)
176193
.catch(function (err) {
177194
self._setAssertError(err);
@@ -183,16 +200,7 @@ Test.prototype.exit = function () {
183200
// stop infinite timer
184201
globals.clearTimeout(self._timeout);
185202

186-
if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertPromises.length) {
187-
self._setAssertError(new assert.AssertionError({
188-
actual: self.assertPromises.length,
189-
expected: self.planCount,
190-
message: 'Assertion count does not match planned',
191-
operator: 'plan'
192-
}));
193-
194-
self.assertError.stack = self.planStack;
195-
}
203+
checkAssertLength();
196204

197205
if (!self.ended) {
198206
self.ended = true;

0 commit comments

Comments
 (0)