From 7964da1739aaafb8c51d6ae5af73247f2c8bd714 Mon Sep 17 00:00:00 2001 From: Takuto Wada Date: Wed, 13 Nov 2019 09:35:44 +0900 Subject: [PATCH] feat: If the validation function passed to assert.throws() or assert.rejects() returns a value other than true, an assertion error will be thrown instead of the original error to highlight the programming mistake refs: https://github.com/nodejs/node/pull/28263 --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 97f7ab6..0fd4d66 100644 --- a/index.js +++ b/index.js @@ -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') {