diff options
author | himself65 <himself65@outlook.com> | 2020-04-26 01:03:50 +0800 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2020-04-28 13:58:29 +0200 |
commit | 6984fbcfca54f4360744247db1ba2c99c51ee987 (patch) | |
tree | b93eb3a9b7154cbf44e243d2ad698985d1308878 | |
parent | c239cc650cb0681f67b8cc47fcd507c4192647e7 (diff) | |
download | node-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.js | 27 |
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`, + }); + }); }); -} |