Skip to content

Commit

Permalink
assert: respect assert.doesNotThrow message.
Browse files Browse the repository at this point in the history
Addresses nodejs#6400.
Special handling to detect when user has supplied a custom message.
Added a test for user message.
  • Loading branch information
diversario committed Nov 6, 2013
1 parent e2da042 commit 667d0fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ function _throws(shouldThrow, block, expected, message) {
fail(actual, expected, 'Missing expected exception' + message);
}

if (!shouldThrow && expectedException(actual, expected)) {
if (!shouldThrow &&
actual instanceof Error &&
typeof message === 'string' &&
expectedException(actual, expected) ||
!shouldThrow && actual && !expected) {
fail(actual, expected, 'Got unwanted exception' + message);
}

Expand Down
7 changes: 7 additions & 0 deletions test/simple/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ assert.throws(function() {assert.ifError(new Error('test error'))});
assert.doesNotThrow(function() {assert.ifError(null)});
assert.doesNotThrow(function() {assert.ifError()});

try {
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
} catch(e) {
assert.equal(e.message, 'Got unwanted exception. user message',
'a.doesNotThrow ignores user message')
}

// make sure that validating using constructor really works
threw = false;
try {
Expand Down

0 comments on commit 667d0fa

Please sign in to comment.