Browse Source

assert: fix incorrect use of ERR_INVALID_ARG_TYPE

PR-URL: https://github.com/nodejs/node/pull/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>
v6
Tobias Nießen 8 years ago
parent
commit
1d7414354e
  1. 2
      lib/assert.js
  2. 14
      test/parallel/test-assert.js

2
lib/assert.js

@ -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') {

14
test/parallel/test-assert.js

@ -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;
@ -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);

Loading…
Cancel
Save