mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
test_runner: fix clearing final timeout in own callback
PR-URL: https://github.com/nodejs/node/pull/52332 Fixes: https://github.com/nodejs/node/issues/52325 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
1 parent
05cb16dc1a
commit
3f8cc88009
2 files changed
+14
-1
No files matched your search
@@ -652,7 +652,7 @@ class MockTimers {
|
||||
|
||||
// Check if the timeout was cleared by calling clearTimeout inside its own callback
|
||||
const afterCallback = this.#executionQueue.peek();
|
||||
if (afterCallback.id === timer.id) {
|
||||
if (afterCallback?.id === timer.id) {
|
||||
this.#executionQueue.shift();
|
||||
timer.priorityQueuePosition = undefined;
|
||||
}
|
||||
|
||||
@@ -548,6 +548,19 @@ describe('Mock Timers Test Suite', () => {
|
||||
t.mock.timers.runAll();
|
||||
assert.strictEqual(f.mock.callCount(), 3);
|
||||
});
|
||||
|
||||
it('should allow clearing timeout inside own callback', (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
const f = t.mock.fn();
|
||||
|
||||
const timer = nodeTimers.setTimeout(() => {
|
||||
f();
|
||||
nodeTimers.clearTimeout(timer);
|
||||
}, 50);
|
||||
|
||||
t.mock.timers.runAll();
|
||||
assert.strictEqual(f.mock.callCount(), 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setInterval Suite', () => {
|
||||
|
||||
Reference in new issue
Block a user