From 252eb2deb239c940081ac20c38ccb9039f136bd3 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 7 Apr 2018 14:20:43 +0200 Subject: [PATCH] assert: fix error message `assert.throws` also accepts objects and errors as input. This fixes the error message accodingly. PR-URL: https://github.com/nodejs/node/pull/19865 Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- lib/assert.js | 4 +++- test/parallel/test-assert.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 9c900fcaf32055..8d22906c5ffc0b 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -465,7 +465,9 @@ async function waitForActual(block) { function expectsError(stackStartFn, actual, error, message) { if (typeof error === 'string') { if (arguments.length === 4) { - throw new ERR_INVALID_ARG_TYPE('error', ['Function', 'RegExp'], error); + throw new ERR_INVALID_ARG_TYPE('error', + ['Object', 'Error', 'Function', 'RegExp'], + error); } message = error; error = null; diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 54972657e94dd4..66851fa5ea7405 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -741,8 +741,8 @@ common.expectsError( { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "error" argument must be one of type Function or RegExp. ' + - 'Received type string' + message: 'The "error" argument must be one of type Object, Error, ' + + 'Function, or RegExp. Received type string' } );