diff --git a/lib/core.js b/lib/core.js index 5281bc735..120c734e2 100644 --- a/lib/core.js +++ b/lib/core.js @@ -65,6 +65,12 @@ exports.runTest = function (name, fn, opt, callback) { var start = new Date().getTime(); var test = types.test(name, start, options, callback); + // Fail the test gracefully if an exception was thrown from a callback + process.removeAllListeners('uncaughtException'); + process.on('uncaughtException', function (exception) { + test.done(exception); + }); + try { fn(test); } diff --git a/lib/types.js b/lib/types.js index 2cdd1efc8..88398b540 100644 --- a/lib/types.js +++ b/lib/types.js @@ -79,12 +79,7 @@ var assertWrapper = function (callback) { return function () { var message = arguments[arity - 1]; var a = exports.assertion({method: new_method, message: message}); - try { - assert[assert_method].apply(null, arguments); - } - catch (e) { - a.error = e; - } + assert[assert_method].apply(null, arguments); callback(a); }; };