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>
This commit is contained in:
himself65 authored and Ruben Bridgewater committed 2020-04-28 13:58:29 +02:00
1 parent c239cc650c
commit 6984fbcfca
1 file changed
+12 -15
+12 -15
View File
@@ -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`,
});
});
});
}