Skip to content

Commit 252eb2d

Browse files
committed
assert: fix error message
`assert.throws` also accepts objects and errors as input. This fixes the error message accodingly. PR-URL: #19865 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 3626944 commit 252eb2d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/assert.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ async function waitForActual(block) {
465465
function expectsError(stackStartFn, actual, error, message) {
466466
if (typeof error === 'string') {
467467
if (arguments.length === 4) {
468-
throw new ERR_INVALID_ARG_TYPE('error', ['Function', 'RegExp'], error);
468+
throw new ERR_INVALID_ARG_TYPE('error',
469+
['Object', 'Error', 'Function', 'RegExp'],
470+
error);
469471
}
470472
message = error;
471473
error = null;

test/parallel/test-assert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,8 @@ common.expectsError(
741741
{
742742
code: 'ERR_INVALID_ARG_TYPE',
743743
type: TypeError,
744-
message: 'The "error" argument must be one of type Function or RegExp. ' +
745-
'Received type string'
744+
message: 'The "error" argument must be one of type Object, Error, ' +
745+
'Function, or RegExp. Received type string'
746746
}
747747
);
748748

0 commit comments

Comments
 (0)