Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var observableToPromise = require('observable-to-promise');
var isPromise = require('is-promise');
var isObservable = require('is-observable');
var assert = require('./assert');
var AvaError = require('./ava-error');
var enhanceAssert = require('./enhance-assert');
var globals = require('./globals');

Expand Down Expand Up @@ -75,10 +76,6 @@ Test.prototype.plan = function (count) {
}

this.planCount = count;

// in case the `planCount` doesn't match `assertCount,
// we need the stack of this function to throw with a useful stack
this.planStack = new Error().stack;
};

Test.prototype.run = function () {
Expand Down Expand Up @@ -174,14 +171,11 @@ Test.prototype._end = function (err) {

Test.prototype._checkPlanCount = function () {
if (this.assertError === undefined && this.planCount !== null && this.planCount !== this.assertions.length) {
this._setAssertError(new assert.AssertionError({
actual: this.assertions.length,
expected: this.planCount,
message: 'Assertion count does not match planned',
operator: 'plan'
}));
var planError = new AvaError('Assertion count of ' + this.assertions.length + ' does not match plan of ' + this.planCount + '.');
planError.actual = this.assertions.length;
planError.expected = this.planCount;

this.assertError.stack = this.planStack;
this._setAssertError(planError);
}
};

Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ test('run more assertions than planned', function (t) {
}).run().catch(function (err) {
t.ok(err);
t.is(err.name, 'AssertionError');
t.match(err.message, / 2( |\,|\.|\!)/, 'includes the expected number of assertions');
t.match(err.message, / 3( |\,|\.|\!)/, 'includes the actual number of assertions');
t.end();
});
});
Expand Down