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;
|
fn = undefined;
|
||||||
}
|
}
|
||||||
function innerFn(error) {
|
function innerFn(error) {
|
||||||
assert.strictEqual(error.code, settings.code);
|
|
||||||
if ('type' in settings) {
|
if ('type' in settings) {
|
||||||
const type = settings.type;
|
const type = settings.type;
|
||||||
if (type !== Error && !Error.isPrototypeOf(type)) {
|
if (type !== Error && !Error.isPrototypeOf(type)) {
|
||||||
@ -714,18 +713,16 @@ exports.expectsError = function expectsError(fn, settings, exact) {
|
|||||||
`${error.message} does not match ${message}`);
|
`${error.message} does not match ${message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ('name' in settings) {
|
|
||||||
assert.strictEqual(error.name, settings.name);
|
// Check all error properties.
|
||||||
}
|
const keys = Object.keys(settings);
|
||||||
if (error.constructor.name === 'AssertionError') {
|
for (const key of keys) {
|
||||||
['generatedMessage', 'actual', 'expected', 'operator'].forEach((key) => {
|
if (key === 'message' || key === 'type')
|
||||||
if (key in settings) {
|
continue;
|
||||||
const actual = error[key];
|
const actual = error[key];
|
||||||
const expected = settings[key];
|
const expected = settings[key];
|
||||||
assert.strictEqual(actual, expected,
|
assert.strictEqual(actual, expected,
|
||||||
`${key}: expected ${expected}, not ${actual}`);
|
`${key}: expected ${expected}, not ${actual}`);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user