summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-async-hooks-constructor.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/parallel/test-async-hooks-constructor.js b/test/parallel/test-async-hooks-constructor.js
new file mode 100644
index 0000000000..f2b4df6a9f
--- /dev/null
+++ b/test/parallel/test-async-hooks-constructor.js
@@ -0,0 +1,23 @@
+'use strict';
+
+// This tests that AsyncHooks throws an error if bad parameters are passed.
+
+const common = require('../common');
+const async_hooks = require('async_hooks');
+const non_function = 10;
+
+typeErrorForFunction('init');
+typeErrorForFunction('before');
+typeErrorForFunction('after');
+typeErrorForFunction('destroy');
+typeErrorForFunction('promiseResolve');
+
+function typeErrorForFunction(functionName) {
+ common.expectsError(() => {
+ async_hooks.createHook({ [functionName]: non_function });
+ }, {
+ code: 'ERR_ASYNC_CALLBACK',
+ type: TypeError,
+ message: `hook.${functionName} must be a function`
+ });
+}