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
PR-URL: #14011
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
tniessen committed Jul 3, 2017
1 parent 8b2c61c commit 1d74143
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 @@ -527,7 +527,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 @@ -669,10 +669,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 @@ -681,7 +680,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 1d74143

Please sign in to comment.