Skip to content

Commit 842747e

Browse files
committed
Include actual and expected when the number of assertions doesn't match the plan.
This isn't as good as it could be, as it doesn't have a nice assertion diff, because that's generated by power assert, which does all kinds of other things too that we don't want
1 parent c7ce760 commit 842747e

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

lib/test.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var observableToPromise = require('observable-to-promise');
88
var isPromise = require('is-promise');
99
var isObservable = require('is-observable');
1010
var assert = require('./assert');
11+
var AvaError = require('./ava-error');
1112
var enhanceAssert = require('./enhance-assert');
1213
var globals = require('./globals');
1314

@@ -75,10 +76,6 @@ Test.prototype.plan = function (count) {
7576
}
7677

7778
this.planCount = count;
78-
79-
// in case the `planCount` doesn't match `assertCount,
80-
// we need the stack of this function to throw with a useful stack
81-
this.planStack = new Error().stack;
8279
};
8380

8481
Test.prototype.run = function () {
@@ -174,14 +171,11 @@ Test.prototype._end = function (err) {
174171

175172
Test.prototype._checkPlanCount = function () {
176173
if (this.assertError === undefined && this.planCount !== null && this.planCount !== this.assertions.length) {
177-
this._setAssertError(new assert.AssertionError({
178-
actual: this.assertions.length,
179-
expected: this.planCount,
180-
message: 'Assertion count does not match planned',
181-
operator: 'plan'
182-
}));
174+
var planError = new AvaError('Assertion count of ' + this.assertions.length + ' does not match plan of ' + this.planCount + '.');
175+
planError.actual = this.assertions.length;
176+
planError.expected = this.planCount;
183177

184-
this.assertError.stack = this.planStack;
178+
this._setAssertError(planError);
185179
}
186180
};
187181

test/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ test('run more assertions than planned', function (t) {
8888
}).run().catch(function (err) {
8989
t.ok(err);
9090
t.is(err.name, 'AssertionError');
91+
t.match(err.message, / 2( |\,|\.|\!)/, 'includes the expected number of assertions');
92+
t.match(err.message, / 3( |\,|\.|\!)/, 'includes the actual number of assertions');
9193
t.end();
9294
});
9395
});

0 commit comments

Comments
 (0)