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: nodejs#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>
  • Loading branch information
BridgeAR committed May 1, 2018
1 parent 297fcf0 commit 188af95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
23 changes: 10 additions & 13 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,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 @@ -704,18 +703,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
5 changes: 1 addition & 4 deletions test/parallel/test-assert-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ common.expectsError(() => {
assert.fail(typeof 1, 'object', new TypeError('another custom message'));
}, {
type: TypeError,
message: 'another custom message',
operator: undefined,
actual: 'number',
expected: 'object'
message: 'another custom message'
});

// No third arg (but a fourth arg)
Expand Down

0 comments on commit 188af95

Please sign in to comment.