Skip to content

Commit 89586f6

Browse files
tniessenaddaleax
authored andcommitted
assert: fix incorrect use of ERR_INVALID_ARG_TYPE
Backport-PR-URL: #14459 Backport-Reviewed-By: Refael Ackermann <[email protected]> PR-URL: #14011 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent bdcd496 commit 89586f6

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ function innerThrows(shouldThrow, block, expected, message) {
521521
if (typeof block !== 'function') {
522522
const errors = lazyErrors();
523523
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'function',
524-
typeof block);
524+
block);
525525
}
526526

527527
if (typeof expected === 'string') {

test/parallel/test-assert.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,9 @@ try {
670670

671671
{
672672
// Verify that throws() and doesNotThrow() throw on non-function block
673-
const validationFunction = common.expectsError({
674-
code: 'ERR_INVALID_ARG_TYPE',
675-
type: TypeError
676-
});
673+
function typeName(value) {
674+
return value === null ? 'null' : typeof value;
675+
}
677676

678677
const testBlockTypeError = (method, block) => {
679678
let threw = true;
@@ -682,7 +681,12 @@ try {
682681
method(block);
683682
threw = false;
684683
} catch (e) {
685-
validationFunction(e);
684+
common.expectsError({
685+
code: 'ERR_INVALID_ARG_TYPE',
686+
type: TypeError,
687+
message: 'The "block" argument must be of type function. Received ' +
688+
'type ' + typeName(block)
689+
})(e);
686690
}
687691

688692
assert.ok(threw);

0 commit comments

Comments
 (0)