Skip to content

Commit 0c354a4

Browse files
committed
assert: fix error message
`assert.throws` also accepts objects and errors as input. This fixes the error message accodingly. PR-URL: nodejs#19865 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 5029b43 commit 0c354a4

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/assert.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222

2323
const { isDeepEqual, isDeepStrictEqual } =
2424
require('internal/util/comparisons');
25-
const { AssertionError, TypeError } = require('internal/errors');
25+
const { AssertionError, TypeError, codes } = require('internal/errors');
26+
const {
27+
ERR_INVALID_ARG_TYPE
28+
} = codes;
2629
const { inspect } = require('util');
2730

2831
const ERR_DIFF_DEACTIVATED = 0;
@@ -282,10 +285,9 @@ async function waitForActual(block) {
282285
function expectsError(stackStartFn, actual, error, message) {
283286
if (typeof error === 'string') {
284287
if (arguments.length === 4) {
285-
throw new TypeError('ERR_INVALID_ARG_TYPE',
286-
'error',
287-
['Function', 'RegExp'],
288-
error);
288+
throw new ERR_INVALID_ARG_TYPE('error',
289+
['Object', 'Error', 'Function', 'RegExp'],
290+
error);
289291
}
290292
message = error;
291293
error = null;

test/parallel/test-assert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ common.expectsError(
599599
{
600600
code: 'ERR_INVALID_ARG_TYPE',
601601
type: TypeError,
602-
message: 'The "error" argument must be one of type Function or RegExp. ' +
603-
'Received type string'
602+
message: 'The "error" argument must be one of type Object, Error, ' +
603+
'Function, or RegExp. Received type string'
604604
}
605605
);
606606

0 commit comments

Comments
 (0)