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

Respect assert.doesNotThrow message. #6469

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,12 @@ function _throws(shouldThrow, block, expected, message) {
if (shouldThrow && !actual) {
fail(actual, expected, 'Missing expected exception' + message);
}

if (!shouldThrow && expectedException(actual, expected)) {

if (!shouldThrow &&
actual instanceof Error &&
util.isString(message) &&
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