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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
himself65 authored and targos committed May 13, 2020
1 parent e0e8a9a commit 60550f3
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 60550f3

Please sign in to comment.