From d7e536d27273f8fb7161a72ee9dadb9a4358f35b 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 80f59333626b9a..89a8c47af9de06 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -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;