From fd9467196f4be75a35fd278e9810fb0fe89db97f Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Wed, 14 Jun 2017 15:47:19 -0400 Subject: [PATCH] test: fix common.expectsError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function should strictly test for the error class and only accept the correct one. Any other error class should fail. PR-URL: https://github.com/nodejs/node/pull/13686 Fixes: https://github.com/nodejs/node/issues/13682 Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso --- test/common/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/common/index.js b/test/common/index.js index 590ffb7b00c2ba..b24d2158e7d089 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -689,6 +689,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;