test: check all properties in common.expectsError
This makes sure all properties that are meant to be checked will actually be tested for. PR-URL: https://github.com/nodejs/node/pull/19722 Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
2f8df6b0f2
commit
2fef227a61
@ -691,7 +691,6 @@ exports.expectsError = function expectsError(fn, settings, exact) {
|
||||
fn = undefined;
|
||||
}
|
||||
function innerFn(error) {
|
||||
assert.strictEqual(error.code, settings.code);
|
||||
if ('type' in settings) {
|
||||
const type = settings.type;
|
||||
if (type !== Error && !Error.isPrototypeOf(type)) {
|
||||
@ -714,18 +713,16 @@ exports.expectsError = function expectsError(fn, settings, exact) {
|
||||
`${error.message} does not match ${message}`);
|
||||
}
|
||||
}
|
||||
if ('name' in settings) {
|
||||
assert.strictEqual(error.name, settings.name);
|
||||
}
|
||||
if (error.constructor.name === 'AssertionError') {
|
||||
['generatedMessage', 'actual', 'expected', 'operator'].forEach((key) => {
|
||||
if (key in settings) {
|
||||
const actual = error[key];
|
||||
const expected = settings[key];
|
||||
assert.strictEqual(actual, expected,
|
||||
`${key}: expected ${expected}, not ${actual}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Check all error properties.
|
||||
const keys = Object.keys(settings);
|
||||
for (const key of keys) {
|
||||
if (key === 'message' || key === 'type')
|
||||
continue;
|
||||
const actual = error[key];
|
||||
const expected = settings[key];
|
||||
assert.strictEqual(actual, expected,
|
||||
`${key}: expected ${expected}, not ${actual}`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user