Skip to content

Commit 8a43ed1

Browse files
committed
squash: add prefix to option name and refact test
1 parent df5ee8f commit 8a43ed1

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

lib/async_hooks.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ const {
4141
class AsyncHook {
4242
constructor({ init, before, after, destroy, promiseResolve }) {
4343
if (init !== undefined && typeof init !== 'function')
44-
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'init');
44+
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.init');
4545
if (before !== undefined && typeof before !== 'function')
46-
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'before');
46+
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.before');
4747
if (after !== undefined && typeof after !== 'function')
48-
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'after');
48+
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.after');
4949
if (destroy !== undefined && typeof destroy !== 'function')
50-
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'destroy');
50+
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.destroy');
5151
if (promiseResolve !== undefined && typeof promiseResolve !== 'function')
52-
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'promiseResolve');
52+
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.promiseResolve');
5353

5454
this[init_symbol] = init;
5555
this[before_symbol] = before;

test/parallel/test-async-hooks-constructor.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,18 @@ const common = require('../common');
66
const async_hooks = require('async_hooks');
77
const non_function = 10;
88

9-
common.expectsError(() => {
10-
async_hooks.createHook({ init: non_function });
11-
}, typeErrorForFunction('init'));
12-
13-
common.expectsError(() => {
14-
async_hooks.createHook({ before: non_function });
15-
}, typeErrorForFunction('before'));
16-
17-
common.expectsError(() => {
18-
async_hooks.createHook({ after: non_function });
19-
}, typeErrorForFunction('after'));
20-
21-
common.expectsError(() => {
22-
async_hooks.createHook({ destroy: non_function });
23-
}, typeErrorForFunction('destroy'));
24-
25-
common.expectsError(() => {
26-
async_hooks.createHook({ promiseResolve: non_function });
27-
}, typeErrorForFunction('promiseResolve'));
9+
typeErrorForFunction('init');
10+
typeErrorForFunction('before');
11+
typeErrorForFunction('after');
12+
typeErrorForFunction('destroy');
13+
typeErrorForFunction('promiseResolve');
2814

2915
function typeErrorForFunction(functionName) {
30-
return {
16+
common.expectsError(() => {
17+
async_hooks.createHook({ [functionName]: non_function });
18+
}, {
3119
code: 'ERR_ASYNC_CALLBACK',
3220
type: TypeError,
33-
message: `${functionName} must be a function`,
34-
};
21+
message: `hook.${functionName} must be a function`
22+
});
3523
}

0 commit comments

Comments
 (0)