Skip to content

Commit edd80e2

Browse files
Aksinya-BykovaRafaelGSS
authored andcommitted
test_runner: do not throw on mocked clearTimeout()
PR-URL: #54005 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent dd3c66b commit edd80e2

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/internal/test_runner/mock/mock_timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class MockTimers {
304304
}
305305

306306
#clearTimer(timer) {
307-
if (timer.priorityQueuePosition !== undefined) {
307+
if (timer?.priorityQueuePosition !== undefined) {
308308
this.#executionQueue.removeAt(timer.priorityQueuePosition);
309309
timer.priorityQueuePosition = undefined;
310310
}

test/parallel/test-runner-mock-timers.js

+23
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ describe('Mock Timers Test Suite', () => {
257257

258258
assert.strictEqual(fn.mock.callCount(), 0);
259259
});
260+
261+
it('clearTimeout does not throw on null and undefined', (t) => {
262+
t.mock.timers.enable({ apis: ['setTimeout'] });
263+
264+
nodeTimers.clearTimeout();
265+
nodeTimers.clearTimeout(null);
266+
});
260267
});
261268

262269
describe('setInterval Suite', () => {
@@ -305,6 +312,13 @@ describe('Mock Timers Test Suite', () => {
305312

306313
assert.strictEqual(fn.mock.callCount(), 0);
307314
});
315+
316+
it('clearInterval does not throw on null and undefined', (t) => {
317+
t.mock.timers.enable({ apis: ['setInterval'] });
318+
319+
nodeTimers.clearInterval();
320+
nodeTimers.clearInterval(null);
321+
});
308322
});
309323

310324
describe('setImmediate Suite', () => {
@@ -372,6 +386,15 @@ describe('Mock Timers Test Suite', () => {
372386
});
373387
});
374388

389+
describe('clearImmediate Suite', () => {
390+
it('clearImmediate does not throw on null and undefined', (t) => {
391+
t.mock.timers.enable({ apis: ['setImmediate'] });
392+
393+
nodeTimers.clearImmediate();
394+
nodeTimers.clearImmediate(null);
395+
});
396+
});
397+
375398
describe('timers/promises', () => {
376399
describe('setTimeout Suite', () => {
377400
it('should advance in time and trigger timers when calling the .tick function multiple times', async (t) => {

0 commit comments

Comments
 (0)