0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-async-hooks-constructor.js
himself65 d027f71100
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>
2020-04-27 19:46:36 +02:00

22 lines
628 B
JavaScript

'use strict';
// This tests that AsyncHooks throws an error if bad parameters are passed.
require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const nonFunctionArray = [null, -1, 1, {}, []];
['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`,
});
});
});