Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
assert: fix throws() throws an error without message property
Browse files Browse the repository at this point in the history
Fixes #2893.
  • Loading branch information
koichik committed Jul 29, 2012
1 parent aa0650f commit 72bc4dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/assert.js
Expand Up @@ -306,11 +306,11 @@ function _throws(shouldThrow, block, expected, message) {
(message ? ' ' + message : '.');

if (shouldThrow && !actual) {
fail('Missing expected exception' + message);
fail(actual, expected, 'Missing expected exception' + message);
}

if (!shouldThrow && expectedException(actual, expected)) {
fail('Got unwanted exception' + message);
fail(actual, expected, 'Got unwanted exception' + message);
}

if ((shouldThrow && actual && expected &&
Expand Down
10 changes: 10 additions & 0 deletions test/simple/test-assert.js
Expand Up @@ -283,3 +283,13 @@ testAssertionMessage({a: undefined, b: null}, '{"a":"undefined","b":null}');
testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
'{"a":"NaN","b":"Infinity","c":"-Infinity"}');

// #2893
try {
assert.throws(function () {
assert.ifError(null);
});
} catch (e) {
threw = true;
assert.equal(e.message, 'Missing expected exception..');
}
assert.ok(threw);

0 comments on commit 72bc4dc

Please sign in to comment.