Skip to content

Commit

Permalink
test: increase util.callbackify() coverage
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cjihrig authored and addaleax committed Jul 11, 2017
1 parent 0264a3a commit 17c1942
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/parallel/test-util-callbackify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}));
});
}

0 comments on commit 17c1942

Please sign in to comment.