Skip to content

Commit 11ea13f

Browse files
himself65BethGriggs
authored andcommitted
test: refactor test-async-hooks-constructor
PR-URL: #33063 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c82c084 commit 11ea13f

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

test/parallel/test-async-hooks-constructor.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@
55
require('../common');
66
const assert = require('assert');
77
const async_hooks = require('async_hooks');
8-
const non_function = 10;
8+
const nonFunctionArray = [null, -1, 1, {}, []];
99

10-
typeErrorForFunction('init');
11-
typeErrorForFunction('before');
12-
typeErrorForFunction('after');
13-
typeErrorForFunction('destroy');
14-
typeErrorForFunction('promiseResolve');
15-
16-
function typeErrorForFunction(functionName) {
17-
assert.throws(() => {
18-
async_hooks.createHook({ [functionName]: non_function });
19-
}, {
20-
code: 'ERR_ASYNC_CALLBACK',
21-
name: 'TypeError',
22-
message: `hook.${functionName} must be a function`
10+
['init', 'before', 'after', 'destroy', 'promiseResolve'].forEach(
11+
(functionName) => {
12+
nonFunctionArray.forEach((nonFunction) => {
13+
assert.throws(() => {
14+
async_hooks.createHook({ [functionName]: nonFunction });
15+
}, {
16+
code: 'ERR_ASYNC_CALLBACK',
17+
name: 'TypeError',
18+
message: `hook.${functionName} must be a function`,
19+
});
20+
});
2321
});
24-
}

0 commit comments

Comments
 (0)