Skip to content

Commit

Permalink
Fix t.plan when the number of assertions is incorrect when the test e…
Browse files Browse the repository at this point in the history
…xits, but is correct once all assertions have resolved
  • Loading branch information
ariporad committed Dec 23, 2015
1 parent 7ffc043 commit 3146d33
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ Test.prototype._end = function (err) {
Test.prototype.exit = function () {
var self = this;

function checkAssertLength() {
if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertPromises.length) {
self._setAssertError(new assert.AssertionError({
actual: self.assertPromises.length,
expected: self.planCount,
message: 'Assertion count does not match planned',
operator: 'plan'
}));

self.assertError.stack = self.planStack;
return false;
}
return true;
}

checkAssertLength();

Promise.all(this.assertPromises)
.catch(function (err) {
self._setAssertError(err);
Expand All @@ -183,16 +200,7 @@ Test.prototype.exit = function () {
// stop infinite timer
globals.clearTimeout(self._timeout);

if (self.assertError === undefined && self.planCount !== null && self.planCount !== self.assertPromises.length) {
self._setAssertError(new assert.AssertionError({
actual: self.assertPromises.length,
expected: self.planCount,
message: 'Assertion count does not match planned',
operator: 'plan'
}));

self.assertError.stack = self.planStack;
}
checkAssertLength();

if (!self.ended) {
self.ended = true;
Expand Down

0 comments on commit 3146d33

Please sign in to comment.