Closed ronny-lark closed 4 months ago
This is usually happening due to multiple instances of @testing-library/dom which is a peer dependency of user-event and a dependency for RTL. Try resolving to one version using npm overrides or yarn resolutions. We're currently working on moving DTL to a peer dependency in RTL too.
@MatanBobi I am also getting this issue too, can you explain how to resolve this. Maybe a code snippet would be great. Thanks
Having the same issue with tests with react 18.3.0. Tried to put "@testing-library/dom": "10.0.0"
to overrides
section of package.json, no luck
Error: Expected test not to call console.error().
If the error is expected, test for it explicitly by mocking it out using jest.spyOn(console, 'error').mockImplementation() and test that the warning occurs.
Warning: `ReactDOMTestUtils.act` is deprecated in favor of `React.act`. Import `act` from `react` instead of `react-dom/test-utils`. See https://react.dev/warnings/react-dom-test-utils for more info.
@belozerov The warning you see here is related to a bug in React's release where they didn't export act
but only unstable_act
as can be seen here: https://github.com/testing-library/react-testing-library/issues/1314.
@brandanking-decently - To verify that it's indeed that problem, you'll need to see if you have multiple version of @testing-library/dom installed. If you do, you'll need to use yarn resolutions of npm overrides to set it to the same version (10), this is defined in your package.json
file.
I'm resolving this as a new version of RTL was released where DTL is a peer dependency so it should resolve it. If you're still experiencing this, please re-open or comment here.
In our app we use Mantine which has a LOT of transitions. We suppress all transitions by setting their duration to 0 in tests, so that we don't have to
await findBy
in every single test.I tried upgrading Vite and Vitest in our project to 5.2 and 1.5 respectively, and at the same time, upgrade
testing-library/react
from 14 to 15, as well as some other supporting libraries.This immediately caused nearly every single test (out of 1500) to start throwing
act
warnings. Sometimes multiple per test. I then started doing a 50/50 to figure out which library upgrade caused this; i.e. upgrading some without the others. Turns out it was@testing-library/react
moving to 15 that caused this issue.Downgrading to 14, while keeping Vite 5.2 and Vitest 1.5 solved the issue, and now all the tests pass without throwing an
act
warning.My question is what could have possibly been changed in V15? I looked at the release notes and there was no mention of anything in particular. Here's my
package.json
: