Skip to content

Commit 2fef227

Browse files
BridgeARlpinca
authored andcommitted
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: #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>
1 parent 2f8df6b commit 2fef227

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

test/common/index.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,6 @@ exports.expectsError = function expectsError(fn, settings, exact) {
691691
fn = undefined;
692692
}
693693
function innerFn(error) {
694-
assert.strictEqual(error.code, settings.code);
695694
if ('type' in settings) {
696695
const type = settings.type;
697696
if (type !== Error && !Error.isPrototypeOf(type)) {
@@ -714,18 +713,16 @@ exports.expectsError = function expectsError(fn, settings, exact) {
714713
`${error.message} does not match ${message}`);
715714
}
716715
}
717-
if ('name' in settings) {
718-
assert.strictEqual(error.name, settings.name);
719-
}
720-
if (error.constructor.name === 'AssertionError') {
721-
['generatedMessage', 'actual', 'expected', 'operator'].forEach((key) => {
722-
if (key in settings) {
723-
const actual = error[key];
724-
const expected = settings[key];
725-
assert.strictEqual(actual, expected,
726-
`${key}: expected ${expected}, not ${actual}`);
727-
}
728-
});
716+
717+
// Check all error properties.
718+
const keys = Object.keys(settings);
719+
for (const key of keys) {
720+
if (key === 'message' || key === 'type')
721+
continue;
722+
const actual = error[key];
723+
const expected = settings[key];
724+
assert.strictEqual(actual, expected,
725+
`${key}: expected ${expected}, not ${actual}`);
729726
}
730727
return true;
731728
}

0 commit comments

Comments
 (0)