From 11ea13f96cc0eba89be6500e96d25a73f9c3a41e Mon Sep 17 00:00:00 2001 From: himself65 Date: Sun, 26 Apr 2020 01:03:50 +0800 Subject: [PATCH] test: refactor test-async-hooks-constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/33063 Reviewed-By: Juan José Arboleda Reviewed-By: James M Snell --- test/parallel/test-async-hooks-constructor.js | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-async-hooks-constructor.js b/test/parallel/test-async-hooks-constructor.js index f6f5c45607fc48..62ec854108e9dc 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`, + }); + }); }); -}