Skip to content

Commit

Permalink
feat: If the validation function passed to assert.throws() or assert.…
Browse files Browse the repository at this point in the history
…rejects() returns a value other than true, an assertion error will be thrown instead of the original error to highlight the programming mistake

refs: nodejs/node#28263
  • Loading branch information
twada committed Apr 18, 2020
1 parent dd01a12 commit 7964da1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ function wantReject (stackStartFn, thennable, errorHandler, message) {
return reject(actualRejectionResult);
}
}
if (errorHandler.call({}, actualRejectionResult) === true) {
var handlerFuncResult = errorHandler.call({}, actualRejectionResult);
if (handlerFuncResult === true) {
return resolve();
} else {
return reject(actualRejectionResult);
return reject(new AssertionError({
actual: actualRejectionResult,
expected: errorHandler,
message: message || 'The validation function is expected to return "true". Received ' + handlerFuncResult + '\n\nCaught error:\n\n' + actualRejectionResult,
operator: stackStartFn.name,
stackStartFn: stackStartFn
}));
}
}
if (typeof errorHandler === 'object') {
Expand Down

0 comments on commit 7964da1

Please sign in to comment.