Skip to content

Commit 1d74143

Browse files
committed
assert: fix incorrect use of ERR_INVALID_ARG_TYPE
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 8b2c61c commit 1d74143

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ function innerThrows(shouldThrow, block, expected, message) {
527527
if (typeof block !== 'function') {
528528
const errors = lazyErrors();
529529
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'function',
530-
typeof block);
530+
block);
531531
}
532532

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

test/parallel/test-assert.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,9 @@ try {
669669

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

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

687691
assert.ok(threw);

0 commit comments

Comments
 (0)