Skip to content

Commit

Permalink
test: check all properties in common.expectsError
Browse files Browse the repository at this point in the history
This makes sure all properties that are meant to be checked will
actually be tested for.

PR-URL: #19722
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
BridgeAR authored and lpinca committed Apr 4, 2018
1 parent 2f8df6b commit 2fef227
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 2fef227

Please sign in to comment.