chore: cleanup global reject handler leaking into tests (#40689)

This commit is contained in:
Robo 2023-12-05 12:56:51 +09:00 committed by GitHub
parent 9afeaa3a4c
commit 3a510a26d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();
});
});
});
});