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: nodejs#13705
  • Loading branch information
cjihrig authored and refack committed Jun 17, 2017
1 parent 3643483 commit ace4ade
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 ace4ade

Please sign in to comment.