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 <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>
  • Loading branch information
cjihrig authored and addaleax committed Jun 21, 2017
1 parent ed01bfe commit d21e4f1
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 d21e4f1

Please sign in to comment.