diff options
author | cjihrig <cjihrig@gmail.com> | 2017-06-15 14:13:39 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2017-06-19 14:33:08 -0400 |
commit | 471e88feb47e8a711e395cf6167d723adf3d1b7a (patch) | |
tree | 6fe236ed013be5e2cb6aa4163c07b5fc997f1b44 /test/parallel/test-util-callbackify.js | |
parent | fd9a30f10ed6fdb797c840b84fe3298f064f1d6b (diff) | |
download | android-node-v8-471e88feb47e8a711e395cf6167d723adf3d1b7a.tar.gz android-node-v8-471e88feb47e8a711e395cf6167d723adf3d1b7a.tar.bz2 android-node-v8-471e88feb47e8a711e395cf6167d723adf3d1b7a.zip |
test: increase util.callbackify() coverage
This commit adds coverage for util.callbackify() type checking.
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'test/parallel/test-util-callbackify.js')
-rw-r--r-- | test/parallel/test-util-callbackify.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js index 65079162c3..68ffc6e920 100644 --- a/test/parallel/test-util-callbackify.js +++ b/test/parallel/test-util-callbackify.js @@ -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' + })); + }); +} |