Browse Source

test: increase util.callbackify() coverage

This commit adds coverage for util.callbackify() type checking.

PR-URL: https://github.com/nodejs/node/pull/13705
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
v6
cjihrig 8 years ago
parent
commit
471e88feb4
  1. 34
      test/parallel/test-util-callbackify.js

34
test/parallel/test-util-callbackify.js

@ -225,3 +225,37 @@ const values = [
})
);
}
{
// Verify that non-function inputs throw.
['foo', null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
assert.throws(() => {
callbackify(value);
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "original" argument must be of type function'
}));
});
}
{
async function asyncFn() {
return await Promise.resolve(42);
}
const cb = callbackify(asyncFn);
const args = [];
// Verify that the last argument to the callbackified function is a function.
['foo', null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
args.push(value);
assert.throws(() => {
cb(...args);
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "last argument" argument must be of type function'
}));
});
}

Loading…
Cancel
Save