assert: provide info about actual error
In case a error is caught in `assert.doesNotThrow` or `assert.doesNotReject` it will now also indicate what the real error message was. PR-URL: https://github.com/nodejs/node/pull/19884 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
5a8fcd0d94
commit
2bee7996a5
@ -510,7 +510,8 @@ function expectsNoError(stackStartFn, actual, error, message) {
|
||||
actual,
|
||||
expected: error,
|
||||
operator: stackStartFn.name,
|
||||
message: `Got unwanted ${fnType}${details}\n${actual && actual.message}`,
|
||||
message: `Got unwanted ${fnType}${details}\n` +
|
||||
`Actual message: "${actual && actual.message}"`,
|
||||
stackStartFn
|
||||
});
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ common.crashOnUnhandledRejection();
|
||||
assert(err instanceof assert.AssertionError,
|
||||
`${err.name} is not instance of AssertionError`);
|
||||
assert.strictEqual(err.code, 'ERR_ASSERTION');
|
||||
assert(/^Got unwanted rejection\.\n$/.test(err.message));
|
||||
assert.strictEqual(err.message,
|
||||
'Got unwanted rejection.\nActual message: ""');
|
||||
assert.strictEqual(err.operator, 'doesNotReject');
|
||||
assert.ok(!err.stack.includes('at Function.doesNotReject'));
|
||||
return true;
|
||||
|
@ -124,29 +124,22 @@ assert.throws(() => thrower(TypeError));
|
||||
assert.ok(threw, 'a.doesNotThrow is not catching type matching errors');
|
||||
}
|
||||
|
||||
common.expectsError(
|
||||
assert.throws(
|
||||
() => a.doesNotThrow(() => thrower(Error), 'user message'),
|
||||
{
|
||||
type: a.AssertionError,
|
||||
name: 'AssertionError [ERR_ASSERTION]',
|
||||
code: 'ERR_ASSERTION',
|
||||
operator: 'doesNotThrow',
|
||||
message: 'Got unwanted exception: user message\n[object Object]'
|
||||
message: 'Got unwanted exception: user message\n' +
|
||||
'Actual message: "[object Object]"'
|
||||
}
|
||||
);
|
||||
|
||||
common.expectsError(
|
||||
() => a.doesNotThrow(() => thrower(Error), 'user message'),
|
||||
{
|
||||
code: 'ERR_ASSERTION',
|
||||
message: /Got unwanted exception: user message\n\[object Object\]/
|
||||
}
|
||||
);
|
||||
|
||||
common.expectsError(
|
||||
assert.throws(
|
||||
() => a.doesNotThrow(() => thrower(Error)),
|
||||
{
|
||||
code: 'ERR_ASSERTION',
|
||||
message: /Got unwanted exception\.\n\[object Object\]/
|
||||
message: 'Got unwanted exception.\nActual message: "[object Object]"'
|
||||
}
|
||||
);
|
||||
|
||||
@ -833,13 +826,13 @@ common.expectsError(
|
||||
|
||||
// eslint-disable-next-line no-throw-literal
|
||||
assert.throws(() => { throw undefined; }, /undefined/);
|
||||
common.expectsError(
|
||||
assert.throws(
|
||||
// eslint-disable-next-line no-throw-literal
|
||||
() => a.doesNotThrow(() => { throw undefined; }),
|
||||
{
|
||||
type: assert.AssertionError,
|
||||
name: 'AssertionError [ERR_ASSERTION]',
|
||||
code: 'ERR_ASSERTION',
|
||||
message: 'Got unwanted exception.\nundefined'
|
||||
message: 'Got unwanted exception.\nActual message: "undefined"'
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user