Browse Source

assert: fix throws() throws an error without message property

Fixes #2893.
v0.8.7-release
koichik 13 years ago
parent
commit
72bc4dcda4
  1. 4
      lib/assert.js
  2. 10
      test/simple/test-assert.js

4
lib/assert.js

@ -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 &&

10
test/simple/test-assert.js

@ -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);

Loading…
Cancel
Save