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 7964da1 commit ed2353d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
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 ed2353d

Please sign in to comment.