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>
This commit is contained in:
parent
fd9a30f10e
commit
471e88feb4
@ -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…
x
Reference in New Issue
Block a user