Skip to content

Commit

Permalink
plan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Nov 25, 2012
1 parent 1ea9057 commit 40aafce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions example/timing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var test = require('../');

test('a simple test', function (t) {
t.plan(2);

t.equal(typeof Date.now, 'function');
var start = Date.now();

setTimeout(function () {
t.equal(Date.now() - start, 100);
}, 100);
});
15 changes: 15 additions & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ Test.prototype.plan = function (n) {

Test.prototype.end = function () {
if (!this.ended) this.emit('end');
if (!this._planError && this.assertCount !== this._plan) {
this._planError = true;
this.fail('plan != count', {
expected : this._plan,
actual : this.assertCount
});
}
this.ended = true;
};

Expand Down Expand Up @@ -68,6 +75,14 @@ Test.prototype._assert = function assert (ok, opts) {
if (!self.ended) self.end();
});
}

if (!self._planError && self.assertCount > self._plan) {
self._planError = true;
self.fail('plan != count', {
expected : self._plan,
actual : self.assertCount
});
}
};

Test.prototype.fail = function (msg, extra) {
Expand Down

0 comments on commit 40aafce

Please sign in to comment.