From aa73271b87f6861544d102f2572ece649cdd0c7b Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Wed, 13 Nov 2019 09:37:09 +0900 Subject: [PATCH] feat: If a constructor function is passed to validate the instance of errors thrown in assert.throws() or assert.reject(), an assertion error will be thrown instead of the original error refs: https://github.com/nodejs/node/pull/28263 --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0fd4d66..5403822 100644 --- a/index.js +++ b/index.js @@ -96,7 +96,13 @@ function wantReject (stackStartFn, thennable, errorHandler, message) { // Dealing with ES2015 class that extends Error // see: https://github.com/nodejs/node/issues/3188 // see: https://github.com/nodejs/node/pull/4166 - return reject(actualRejectionResult); + return reject(new AssertionError({ + actual: actualRejectionResult, + expected: errorHandler, + message: message || 'The error is expected to be an instance of "' + errorHandler.name + '". Received "' + actualRejectionResult.constructor.name + '"\n\nError message:\n\n' + actualRejectionResult.message, + operator: stackStartFn.name, + stackStartFn: stackStartFn + })); } } var handlerFuncResult = errorHandler.call({}, actualRejectionResult);