Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test_runner: do not throw on mocked clearTimeout()
  • Loading branch information
Aksinya-Bykova committed Jul 23, 2024
commit c52bc4e7633174ff83c9138f83a225274a1f9f02
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