Skip to content

Commit

Permalink
chore: sync with upstream changes in validation function message
Browse files Browse the repository at this point in the history
  • Loading branch information
twada committed Apr 18, 2020
1 parent 2306eec commit 96ab856
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -109,10 +109,11 @@ function wantReject (stackStartFn, thennable, errorHandler, message) {
if (handlerFuncResult === true) {
return resolve();
} else {
var validationFunctionName = errorHandler.name ? 'The "' + errorHandler.name + '" validation function' : 'The validation function';
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,
message: message || validationFunctionName + ' is expected to return "true". Received ' + handlerFuncResult + '\n\nCaught error:\n\n' + actualRejectionResult,
operator: stackStartFn.name,
stackStartFn: stackStartFn
}));
Expand Down
14 changes: 8 additions & 6 deletions test/test.js
Expand Up @@ -282,17 +282,19 @@ implementations.forEach(function (impl) {
} else {
it('when returned value of validation function is NOT `true`, rejects with AssertionError.', function () {
var e = new RangeError('Wrong range');
const handlerFn = (err) => {
return ((err instanceof TypeError) && /type/.test(err));
};
return rejects(
willReject(e),
function (err) {
return ((err instanceof TypeError) && /type/.test(err));
}
handlerFn
).then(shouldNotBeFulfilled, function (err) {
assert(err instanceof assert.AssertionError);
assert.equal(err.actual, e);
// assert.equal(err.expected, handler);
assert(/The validation function is expected to return "true". Received false/.test(err.message));
assert(/RangeError: Wrong range/.test(err.message));
assert.equal(err.expected, handlerFn);

assert(/The "handlerFn" validation function is expected to return "true". Received false/.test(err.message), `actual [${err.message}]`);
assert(/RangeError: Wrong range/.test(err.message), `actual [${err.message}]`);
});
});
}
Expand Down

0 comments on commit 96ab856

Please sign in to comment.