Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: refactor test-async-hooks-constructor
  • Loading branch information
himself65 committed Apr 25, 2020
commit 443d9fc3f408bfbd94db0a084903a9bee7d38f5c
27 changes: 12 additions & 15 deletions test/parallel/test-async-hooks-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
});
});
});
}