From 17c194282c99504c634a1614ffb2df4d3fb0c849 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 15 Jun 2017 14:13:39 -0400 Subject: [PATCH] test: increase util.callbackify() coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds coverage for util.callbackify() type checking. PR-URL: https://github.com/nodejs/node/pull/13705 Reviewed-By: James M Snell Reviewed-By: Tobias Nießen Reviewed-By: Refael Ackermann Reviewed-By: Benjamin Gruenbaum --- test/parallel/test-util-callbackify.js | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/parallel/test-util-callbackify.js b/test/parallel/test-util-callbackify.js index 8bbc0fd36e970a..a385538159c8a8 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' + })); + }); +}