Skip to content

Commit

Permalink
test: fix common.expectsError
Browse files Browse the repository at this point in the history
The function should strictly test for the error class and only accept
the correct one. Any other error class should fail.

PR-URL: #13686
Fixes: #13682
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
refack authored and MylesBorins committed Jan 8, 2018
1 parent a069f44 commit d7e536d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ exports.expectsError = function expectsError(fn, settings, exact) {
}
assert(error instanceof type,
`${error.name} is not instance of ${type.name}`);
let typeName = error.constructor.name;
if (typeName === 'NodeError' && type.name !== 'NodeError') {
typeName = Object.getPrototypeOf(error.constructor).name;
}
assert.strictEqual(typeName, type.name);
}
if ('message' in settings) {
const message = settings.message;
Expand Down

0 comments on commit d7e536d

Please sign in to comment.