-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: increase util.callbackify() coverage #13705
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the return itself is already sufficient as the return value is implicitly wrapped in a promise. Therefore the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, but that's the way to other tests are written (e.g. https://github.com/nodejs/node/blob/master/test/parallel/test-util-callbackify.js#L31) |
||
} | ||
|
||
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this output is a tiny bit unfortunate 🤷♂️ I should have covered this |
||
})); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit: could use
values.filter(v => typeof v !== 'function')