Skip to content

Commit

Permalink
feat: If a constructor function is passed to validate the instance of…
Browse files Browse the repository at this point in the history
… errors thrown in assert.throws() or assert.reject(), an assertion error will be thrown instead of the original error

refs: nodejs/node#28263
  • Loading branch information
twada committed Apr 18, 2020
1 parent 6624cc1 commit aa73271
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -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);
Expand Down

0 comments on commit aa73271

Please sign in to comment.