Skip to content

Commit

Permalink
assert: fix incorrect use of ERR_INVALID_ARG_TYPE
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tniessen authored and addaleax committed Jul 27, 2017
1 parent bdcd496 commit 89586f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ function innerThrows(shouldThrow, block, expected, message) {
if (typeof block !== 'function') {
const errors = lazyErrors();
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'function',
typeof block);
block);
}

if (typeof expected === 'string') {
Expand Down
14 changes: 9 additions & 5 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,9 @@ try {

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

const testBlockTypeError = (method, block) => {
let threw = true;
Expand All @@ -682,7 +681,12 @@ try {
method(block);
threw = false;
} catch (e) {
validationFunction(e);
common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "block" argument must be of type function. Received ' +
'type ' + typeName(block)
})(e);
}

assert.ok(threw);
Expand Down

0 comments on commit 89586f6

Please sign in to comment.