Skip to content

Commit

Permalink
Fix: Failing test should not affect others
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Nov 17, 2011
1 parent d363705 commit 7ca43f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/TestCase.js
Expand Up @@ -18,13 +18,14 @@ TestCase.prototype.run = function() {

var fn = this._tests[test];
var context = {};
var err = null;

try {
before.call(context);
fn.call(context);
after.call(context);
} catch (_err) {
var err = _err;
err = _err;
}

if (!err) {
Expand Down
28 changes: 28 additions & 0 deletions test/unit/test-TestCase.js
Expand Up @@ -74,3 +74,31 @@ var TestCase = require('../../lib/TestCase');

assert.ok(aCalled);
})();

(function testErrorInOneTestDoesNotAffectOthers() {
var test = new TestCase({tests: {
a: function() {
assert.equal(2, 1);
},
b: function() {
assert.equal(1, 1);
},
}});

var fail = [];
var pass = [];

test
.on('pass', function(name) {
pass.push(name);
})
.on('fail', function(name, err) {
fail.push(name);
});


test.run();

assert.deepEqual(pass, ['b']);
assert.deepEqual(fail, ['a']);
})();

0 comments on commit 7ca43f8

Please sign in to comment.