xref: /third_party/node/test/parallel/test-async-hooks-constructor.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// This tests that AsyncHooks throws an error if bad parameters are passed.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cirequire('../common');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks');
81cb0ef41Sopenharmony_ciconst nonFunctionArray = [null, -1, 1, {}, []];
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci['init', 'before', 'after', 'destroy', 'promiseResolve'].forEach(
111cb0ef41Sopenharmony_ci  (functionName) => {
121cb0ef41Sopenharmony_ci    nonFunctionArray.forEach((nonFunction) => {
131cb0ef41Sopenharmony_ci      assert.throws(() => {
141cb0ef41Sopenharmony_ci        async_hooks.createHook({ [functionName]: nonFunction });
151cb0ef41Sopenharmony_ci      }, {
161cb0ef41Sopenharmony_ci        code: 'ERR_ASYNC_CALLBACK',
171cb0ef41Sopenharmony_ci        name: 'TypeError',
181cb0ef41Sopenharmony_ci        message: `hook.${functionName} must be a function`,
191cb0ef41Sopenharmony_ci      });
201cb0ef41Sopenharmony_ci    });
211cb0ef41Sopenharmony_ci  });
22

Indexes created Thu Nov 07 10:32:03 CST 2024