From 3a510a26d0ecea026f8f142ae69307064cd59b6d Mon Sep 17 00:00:00 2001 From: Robo Date: Tue, 5 Dec 2023 12:56:51 +0900 Subject: [PATCH] chore: cleanup global reject handler leaking into tests (#40689) --- spec/node-spec.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/spec/node-spec.ts b/spec/node-spec.ts index 2f8dd5218d5..744d8f9dd14 100644 --- a/spec/node-spec.ts +++ b/spec/node-spec.ts @@ -867,22 +867,23 @@ describe('node feature', () => { }); it('performs microtask checkpoint correctly', (done) => { + let timer : NodeJS.Timeout; + const listener = () => { + done(new Error('catch block is delayed to next tick')); + }; + const f3 = async () => { return new Promise((resolve, reject) => { + timer = setTimeout(listener); reject(new Error('oops')); }); }; - let called = false; - process.once('unhandledRejection', () => { - if (called) return; - - done(new Error('catch block is delayed to next tick')); - called = true; - }); - setTimeout(() => { - f3().catch(() => done()); + f3().catch(() => { + clearTimeout(timer); + done(); + }); }); }); });