diff --git a/lib/test.js b/lib/test.js index 538cbcdd..d4b4b1cc 100644 --- a/lib/test.js +++ b/lib/test.js @@ -446,7 +446,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { fn(); } catch (err) { caught = { error : err }; - if (!isEnumerable(err, 'message') || !has(err, 'message')) { + if ((err != null) && (!isEnumerable(err, 'message') || !has(err, 'message'))) { var message = err.message; delete err.message; err.message = message; diff --git a/test/throws.js b/test/throws.js index 77273d43..31ab9a45 100644 --- a/test/throws.js +++ b/test/throws.js @@ -98,9 +98,11 @@ tap.test('failures', function (tt) { + 'ok 10 "message" is enumerable\n' + "ok 11 { custom: 'error', message: 'message' }\n" + 'ok 12 getter is still the same\n' - + '\n1..12\n' - + '# tests 12\n' - + '# pass 3\n' + + '# throws null\n' + + 'ok 13 throws null\n' + + '\n1..13\n' + + '# tests 13\n' + + '# pass 4\n' + '# fail 9\n' ); })); @@ -134,4 +136,10 @@ tap.test('failures', function (tt) { t.throws(function () { throw messageGetterError; }, "{ custom: 'error', message: 'message' }"); t.equal(Object.getOwnPropertyDescriptor(messageGetterError, 'message').get, getter, 'getter is still the same'); }); + + test('throws null', function (t) { + t.plan(1); + t.throws(function () { throw null; }, 'throws null'); + t.end(); + }); });