Skip to content

How to fix warning An update to TimerRoot inside a test was not wrapped in act(...) with timers? #1348

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

Open
blasdfaa opened this issue Jan 18, 2025 · 1 comment

Comments

@blasdfaa
Copy link

tests are running correctly, but a warning appears in console. How can I fix this?

Warning: An update to TimerRoot inside a test was not wrapped in act(...).

When testing, code that causes React state updates should be wrapped into act(...):

act(() => {
  /* fire events that update state */
});
/* assert on the output */

Demo - https://stackblitz.com/edit/vitejs-vite-7zbv1rkb?file=src%2FApp.test.tsx
Run npm run test

@temm1210
Copy link

temm1210 commented May 5, 2025

vi.advanceTimersByTime is sync timer.
if u want async timer, use vi.advanceTimersByTimeAsync

await act(async () => vi.advanceTimersByTimeAsync(1000));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants