Skip to content
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
6 changes: 5 additions & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,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/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,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