-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useFakeTimers isn't working for the setInterval. #897
Comments
Hey @gsamal! I'm here to help you with any bugs, questions, or contributions you may have. Let's work together to solve this issue! The issue you're encountering with
To address this issue, you can try the following steps:
Here is an example of how you might modify your test to ensure describe('Testing timers', () => {
let triggered = false;
beforeAll(() => {
vi.useFakeTimers();
if (import.meta.client) {
setInterval(() => {
triggered = true;
}, 1000);
}
});
afterAll(() => {
vi.useRealTimers();
});
it.only('Should trigger the timer', () => {
vi.advanceTimersByTime(1000);
expect(triggered).toEqual(true); // Should pass if setInterval is called on the client side
});
}); This ensures that |
When I tried with |
No, there is no configuration in Nuxt to prevent it from using its custom |
Using window.setInterval is definitely not a good idea. |
Environment
Reproduction
Non-working code with setInterval -
Working with setTimeout
Reproduction - https://stackblitz.com/edit/github-agxb9y-xks33q?file=test%2Fapp.nuxt.spec.ts
Works without nuxt - https://stackblitz.com/edit/vitest-dev-vitest-hr7i1i?file=test%2Ftimer.test.ts
Describe the bug
setInterval
isn't triggering withfakeTimer
, howeversetTimeout
does. I have triedadvanceTimersByTime
,advanceTimersToNextTimer
andrunAllTimers
but doesn't help.Note - I don't find this issue with the Vitest itself. using
defineVitestConfig
is causing this behaviour.Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: