Skip to content

Commit

Permalink
test_runner: do not throw on mocked clearTimeout()
Browse files Browse the repository at this point in the history
PR-URL: #54005
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
Aksinya-Bykova authored and RafaelGSS committed Aug 5, 2024
1 parent dd3c66b commit edd80e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/mock/mock_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class MockTimers {
}

#clearTimer(timer) {
if (timer.priorityQueuePosition !== undefined) {
if (timer?.priorityQueuePosition !== undefined) {
this.#executionQueue.removeAt(timer.priorityQueuePosition);
timer.priorityQueuePosition = undefined;
}
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-runner-mock-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ describe('Mock Timers Test Suite', () => {

assert.strictEqual(fn.mock.callCount(), 0);
});

it('clearTimeout does not throw on null and undefined', (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] });

nodeTimers.clearTimeout();
nodeTimers.clearTimeout(null);
});
});

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

assert.strictEqual(fn.mock.callCount(), 0);
});

it('clearInterval does not throw on null and undefined', (t) => {
t.mock.timers.enable({ apis: ['setInterval'] });

nodeTimers.clearInterval();
nodeTimers.clearInterval(null);
});
});

describe('setImmediate Suite', () => {
Expand Down Expand Up @@ -372,6 +386,15 @@ describe('Mock Timers Test Suite', () => {
});
});

describe('clearImmediate Suite', () => {
it('clearImmediate does not throw on null and undefined', (t) => {
t.mock.timers.enable({ apis: ['setImmediate'] });

nodeTimers.clearImmediate();
nodeTimers.clearImmediate(null);
});
});

describe('timers/promises', () => {
describe('setTimeout Suite', () => {
it('should advance in time and trigger timers when calling the .tick function multiple times', async (t) => {
Expand Down

0 comments on commit edd80e2

Please sign in to comment.