Testing · Middle · Question 9 of 75
How do you fix the current date in a test?
- ✓Correct answer:
vi.useFakeTimers(); vi.setSystemTime(new Date("2026-01-01"))(in Jest:jest.setSystemTime) - 2Change the computer's clock in CI
- 3Mock
Date.nowonly -new Date()will follow
Explanation
Code that shows “today” or computes expiry otherwise fails on certain dates or in other time zones.