xref: /third_party/node/test/parallel/test-promise-hook-on-after.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { promiseHooks } = require('v8');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciassert.throws(() => {
71cb0ef41Sopenharmony_ci  promiseHooks.onAfter(async function() { });
81cb0ef41Sopenharmony_ci}, /The "afterHook" argument must be of type function/);
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciassert.throws(() => {
111cb0ef41Sopenharmony_ci  promiseHooks.onAfter(async function*() { });
121cb0ef41Sopenharmony_ci}, /The "afterHook" argument must be of type function/);
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cilet seen;
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst stop = promiseHooks.onAfter(common.mustCall((promise) => {
171cb0ef41Sopenharmony_ci  seen = promise;
181cb0ef41Sopenharmony_ci}, 1));
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciconst promise = Promise.resolve().then(() => {
211cb0ef41Sopenharmony_ci  assert.strictEqual(seen, undefined);
221cb0ef41Sopenharmony_ci});
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cipromise.then(() => {
251cb0ef41Sopenharmony_ci  assert.strictEqual(seen, promise);
261cb0ef41Sopenharmony_ci  stop();
271cb0ef41Sopenharmony_ci});
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciassert.strictEqual(seen, undefined);
30

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