A lot of React Warnings Warning: An update to ... inside a test was not wrapped in act(...).
appeared since 3.0.0-beta.2 (fixed in 3.0.2)
#7283
Labels
Describe the bug
Note: This seems to be already fixed with the just released
v3.0.2
and can immediately be closed if you also consider this to be intentionally fixed withv3.0.2
.However I still thought reporting this as a reference might be worth as others might also face this issue after updating to v3 and search for a solution. Besides that, I think it might be worth mentioning that this appeared after the v3 update as I am not sure by the changelog for
v3.0.2
what exactly fixed it. I guess #7281 fixed it.Bug description:
Since updating to vite v3 (tested
v3.0.1
), a lot of the following react warning appeared in quite some existing tests that would not emit that warning with vitest <=3.0.0-beta.1
.I traced it down that these warnings started to be emitted with vitest
3.0.0-beta.2
.Again, after updating to v3.0.2, the issue was gone in my existing tests.
Reproduction
This is kind of a reproduction that creates such a warning.
It is based on the reproduction in #7196 and causes an update to the
Button
react component after 400ms.https://stackblitz.com/edit/vitest-fake-timers-act-warnings-trw1va8q?file=src%2FButton.test.tsx
Such a promise at the end of a test is not used in my regular tests, however, that was how I could trigger this warning in the repro.
However, I am unsure whether this is really a good repro of the issue as it kind of intentionally makes the react component to update after the test completed. Still, I thought
testing-library/react
would callcleanup
in a globalafterEach
after each test which should prevent this.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: