mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
assert: respect assert.doesNotThrow message.
Special handling to detect when user has supplied a custom message. Added a test for user message. When testing if `actual` value is an error use `util.isError` instead of `instanceof`. Fixes: https://github.com/nodejs/node/issues/2385 PR-URL: https://github.com/nodejs/node/pull/2407 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
9a9beefe23
commit
c1d82ac2ff
@ -330,7 +330,14 @@ function _throws(shouldThrow, block, expected, message) {
|
||||
fail(actual, expected, 'Missing expected exception' + message);
|
||||
}
|
||||
|
||||
if (!shouldThrow && expectedException(actual, expected)) {
|
||||
const userProvidedMessage = typeof message === 'string';
|
||||
const isUnwantedException = !shouldThrow && util.isError(actual);
|
||||
const isUnexpectedException = !shouldThrow && actual && !expected;
|
||||
|
||||
if ((isUnwantedException &&
|
||||
userProvidedMessage &&
|
||||
expectedException(actual, expected)) ||
|
||||
isUnexpectedException) {
|
||||
fail(actual, expected, 'Got unwanted exception' + message);
|
||||
}
|
||||
|
||||
|
@ -321,6 +321,11 @@ assert.throws(function() {assert.ifError(new Error('test error'));});
|
||||
assert.doesNotThrow(function() {assert.ifError(null);});
|
||||
assert.doesNotThrow(function() {assert.ifError();});
|
||||
|
||||
assert.throws(() => {
|
||||
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
|
||||
}, /Got unwanted exception. user message/,
|
||||
'a.doesNotThrow ignores user message');
|
||||
|
||||
// make sure that validating using constructor really works
|
||||
threw = false;
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user