You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Warning: The current testing environment is not configured to support act(...) #1336
I'm not sure why you didn't get the above before, but this should be resolved by using yarn resolutions and enforcing the same version for DTL. The reason this is probably happening to you is because you still have multiple version of DTL installed due to @storybook/testing-library installing an older version of DTL.
Sadly that didn't help, at least with v10. testing-library/react v15 works for now. Maybe the issue isn't the dom library, but something else with v16? All I have to do to fix this is downgrade to v15.0,7.
# Upgrade "react" one like OP
"@testing-library/dom": "9.3.4"
"@testing-library/react": "16.0.0",
# Latest of both packages
"@testing-library/dom": "10.1.0"
"@testing-library/react": "16.0.0",
# Upgrading "dom" but staying on v15.x
"@testing-library/dom": "10.1.0"
"@testing-library/react": "15.0.7",
Also using vitest like OP but not @testing-library/jest
Instead @testing-library/jest-dom (not my repo so idk if it matters)
@ryanlelek The issue you're experiencing isn't related to the version of testing library AFAIU. A few things I saw in your tests:
You don't need to wrap any interaction with act, this is done for you as long as you're using @testing-library/react.
After removing all of the await act you had there, the only test that triggers the error is you're last test. Refactoring it this way removes the error:
test("AudioRecorder timer works properly", async () => {
const user = userEvent.setup();
const onRecordingComplete = vi.fn();
render(<AudioRecorder onRecordingComplete={onRecordingComplete} />);
const audioRecorder: HTMLElement = screen.getByTestId("audio_recorder");
const audioRecorderMic: HTMLElement = screen.getByTestId("ar_mic");
await user.click(audioRecorderMic);
expect(audioRecorder).toHaveClass("recording");
const audioRecorderTimer: HTMLElement = screen.getByTestId("ar_timer");
expect(audioRecorder).toHaveClass("recording"); // should still be recording after pause
await waitFor(() => {
expect(audioRecorderTimer.textContent).toEqual("0:01"); // timer should have gone to 1 sec
});
await user.click(audioRecorderMic);
expect(audioRecorder.classList.contains("recording")).toBeFalsy();
expect(onRecordingComplete).toHaveBeenCalled();
expect(getTracks).toHaveBeenCalled();
expect(stop).toHaveBeenCalled();
});
Btw, I highly recommend not waiting 1 second in your tests and use fake timers instead.
Anyway to fix this other than sticking to v15 pls?
I just learned that I don't need act everywhere on the latest version and I am very happy. But a little aggravated given I added it everywhere to appease the framework because I used to get an error saying I need it before 🙃
But a huge win for my other project where we ignored the error about needing to wrap it in Act 🤣
Activity
MatanBobi commentedon Jun 19, 2024
I'm not sure why you didn't get the above before, but this should be resolved by using yarn
resolutionsand enforcing the same version for DTL. The reason this is probably happening to you is because you still have multiple version of DTL installed due to@storybook/testing-libraryinstalling an older version of DTL.viveleroi commentedon Jun 19, 2024
Sadly that didn't help, at least with v10. testing-library/react v15 works for now. Maybe the issue isn't the dom library, but something else with v16? All I have to do to fix this is downgrade to v15.0,7.
ryanlelek commentedon Jun 20, 2024
Chiming in with this issue also and some info.
Using npm (fresh install, no lockfile).
Works fine. Current solution is to use this while we investigate
All of these combinations have the issue
Also using
vitestlike OP but not@testing-library/jestInstead
@testing-library/jest-dom(not my repo so idk if it matters)Most other dependencies are up-to-date, except for eslint+ ffmpeg (unrelated)
Output of
npm outdatedLink to repo if you want an example (branch: dependencies)
https://github.com/ryanlelek/react-audio-recorder/tree/dependencies
MatanBobi commentedon Jun 20, 2024
@viveleroi Can you please provide a reproduction for this one so we'll be able to investigate?
You can use https://testing-library.com/new-rtl
@ryanlelek The issue you're experiencing isn't related to the version of testing library AFAIU. A few things I saw in your tests:
act, this is done for you as long as you're using@testing-library/react.await actyou had there, the only test that triggers the error is you're last test. Refactoring it this way removes the error:Btw, I highly recommend not waiting 1 second in your tests and use fake timers instead.
OlaoluwaM commentedon Jul 17, 2024
One solution has been removing the flagged
actcallswhoisahmed commentedon Dec 19, 2024
Anyway to fix this other than sticking to v15 pls?
MatanBobi commentedon Dec 19, 2024
@whoisahmed We'll need a reproduction to understand what you're experiencing.
R-Sandor commentedon Dec 21, 2024
I just learned that I don't need act everywhere on the latest version and I am very happy. But a little aggravated given I added it everywhere to appease the framework because I used to get an error saying I need it before 🙃
But a huge win for my other project where we ignored the error about needing to wrap it in Act 🤣