0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-promise-hook-on-before.js
Stephen Belanger da82844493 v8: multi-tenant promise hook api
PR-URL: https://github.com/nodejs/node/pull/39283
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2021-11-01 11:08:59 -07:00

28 lines
640 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { promiseHooks } = require('v8');
assert.throws(() => {
promiseHooks.onBefore(async function() { });
}, /The "beforeHook" argument must be of type function/);
assert.throws(() => {
promiseHooks.onBefore(async function*() { });
}, /The "beforeHook" argument must be of type function/);
let seen;
const stop = promiseHooks.onBefore(common.mustCall((promise) => {
seen = promise;
}, 1));
const promise = Promise.resolve().then(() => {
assert.strictEqual(seen, promise);
stop();
});
promise.then();
assert.strictEqual(seen, undefined);