summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhimself65 <himself65@outlook.com>2020-04-26 01:03:50 +0800
committerRuben Bridgewater <ruben@bridgewater.de>2020-04-28 13:58:29 +0200
commit6984fbcfca54f4360744247db1ba2c99c51ee987 (patch)
treeb93eb3a9b7154cbf44e243d2ad698985d1308878
parentc239cc650cb0681f67b8cc47fcd507c4192647e7 (diff)
downloadnode-new-6984fbcfca54f4360744247db1ba2c99c51ee987.tar.gz
test: refactor test-async-hooks-constructor
PR-URL: https://github.com/nodejs/node/pull/33063 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--test/parallel/test-async-hooks-constructor.js27
1 files changed, 12 insertions, 15 deletions
diff --git a/test/parallel/test-async-hooks-constructor.js b/test/parallel/test-async-hooks-constructor.js
index f6f5c45607..62ec854108 100644
--- a/test/parallel/test-async-hooks-constructor.js
+++ b/test/parallel/test-async-hooks-constructor.js
@@ -5,20 +5,17 @@
require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
-const non_function = 10;
+const nonFunctionArray = [null, -1, 1, {}, []];
-typeErrorForFunction('init');
-typeErrorForFunction('before');
-typeErrorForFunction('after');
-typeErrorForFunction('destroy');
-typeErrorForFunction('promiseResolve');
-
-function typeErrorForFunction(functionName) {
- assert.throws(() => {
- async_hooks.createHook({ [functionName]: non_function });
- }, {
- code: 'ERR_ASYNC_CALLBACK',
- name: 'TypeError',
- message: `hook.${functionName} must be a function`
+['init', 'before', 'after', 'destroy', 'promiseResolve'].forEach(
+ (functionName) => {
+ nonFunctionArray.forEach((nonFunction) => {
+ assert.throws(() => {
+ async_hooks.createHook({ [functionName]: nonFunction });
+ }, {
+ code: 'ERR_ASYNC_CALLBACK',
+ name: 'TypeError',
+ message: `hook.${functionName} must be a function`,
+ });
+ });
});
-}