Skip to content

Commit bf22514

Browse files
cjihrigaddaleax
authored andcommitted
test: increase util.callbackify() coverage
This commit adds coverage for util.callbackify() type checking. PR-URL: #13705 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent e8780ba commit bf22514

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/parallel/test-util-callbackify.js

+34
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,37 @@ const values = [
225225
})
226226
);
227227
}
228+
229+
{
230+
// Verify that non-function inputs throw.
231+
['foo', null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
232+
assert.throws(() => {
233+
callbackify(value);
234+
}, common.expectsError({
235+
code: 'ERR_INVALID_ARG_TYPE',
236+
type: TypeError,
237+
message: 'The "original" argument must be of type function'
238+
}));
239+
});
240+
}
241+
242+
{
243+
async function asyncFn() {
244+
return await Promise.resolve(42);
245+
}
246+
247+
const cb = callbackify(asyncFn);
248+
const args = [];
249+
250+
// Verify that the last argument to the callbackified function is a function.
251+
['foo', null, undefined, false, 0, {}, Symbol(), []].forEach((value) => {
252+
args.push(value);
253+
assert.throws(() => {
254+
cb(...args);
255+
}, common.expectsError({
256+
code: 'ERR_INVALID_ARG_TYPE',
257+
type: TypeError,
258+
message: 'The "last argument" argument must be of type function'
259+
}));
260+
});
261+
}

0 commit comments

Comments
 (0)