assert: show thrown message in doesNotThrow()
assert.doesNotThrow() should show actual error message instead of "Got unwanted exception" which is not really helpful. PR-URL: https://github.com/nodejs/node/pull/12167 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
parent
2a621d4051
commit
c53db1e8e9
@ -546,7 +546,10 @@ function innerThrows(shouldThrow, block, expected, message) {
|
||||
} else if (actual !== undefined) {
|
||||
if (!expected || expectedException(actual, expected)) {
|
||||
details = message ? `: ${message}` : '.';
|
||||
fail(actual, expected, `Got unwanted exception${details}`, fail);
|
||||
fail(actual,
|
||||
expected,
|
||||
`Got unwanted exception${details}\n${actual.message}`,
|
||||
fail);
|
||||
}
|
||||
throw actual;
|
||||
}
|
||||
|
@ -468,6 +468,34 @@ assert.throws(() => {
|
||||
}, /Got unwanted exception: user message/,
|
||||
'a.doesNotThrow ignores user message');
|
||||
|
||||
{
|
||||
let threw = false;
|
||||
try {
|
||||
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
common.expectsError({
|
||||
code: 'ERR_ASSERTION',
|
||||
message: /Got unwanted exception: user message\n\[object Object\]/
|
||||
})(e);
|
||||
}
|
||||
assert.ok(threw);
|
||||
}
|
||||
|
||||
{
|
||||
let threw = false;
|
||||
try {
|
||||
assert.doesNotThrow(makeBlock(thrower, Error));
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
common.expectsError({
|
||||
code: 'ERR_ASSERTION',
|
||||
message: /Got unwanted exception\.\n\[object Object\]/
|
||||
})(e);
|
||||
}
|
||||
assert.ok(threw);
|
||||
}
|
||||
|
||||
// make sure that validating using constructor really works
|
||||
{
|
||||
let threw = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user