Skip to content

Commit

Permalink
test: refactor test-async-hooks-constructor
Browse files Browse the repository at this point in the history
PR-URL: #33063
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
himself65 authored and BridgeAR committed Apr 28, 2020
1 parent c239cc6 commit 6984fbc
Showing 1 changed file with 12 additions and 15 deletions.
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`,
});
});
});
}

0 comments on commit 6984fbc

Please sign in to comment.