mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
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:
1 parent
c239cc650c
commit
6984fbcfca
1 file changed
+12
-15
@@ -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`,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user