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
RTL + Vitest issue with patching asyncWrapper/eventWrapper (with act()) for userEvent APIs #1338
We've discovered that when using latest versions of Vitest, RTL, and userEvent the userEvent APIs are not patched with act() and this results in "not wrapped in act()" warnings.
testing simple MUI component interactions with userEvent.setup() APIs.
What happened:
All interactions result in the "not wrapped in act() warning":
stderr | src/select.spec.jsx > Select > works with user interactions
Warning: An update to ForwardRef(FormControl) 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 */
You can rerun the test with npm test.
Note that the first test passes but the second one will not. I skipped the failing test because the stack trace is harder to read.
Problem description:
IIUC RTL is supposed to "monkey patch" DTL's config so that all userEvent APIs are wrapped in act() and this is not happening with Vitest.
Suggested solution:
We (cc @kiel-nokia) stepped through all the code to debug this and I'm not sure we have an easy/simple solution to present as this looks like a runtime side effects issue.
changed the title [-]RTL issue with patching asyncWrapper/eventWrapper (with act()) for userEvent API in Vitest[/-][+]RTL + Vitest issue with patching asyncWrapper/eventWrapper (with act()) for userEvent APIs[/+]on Jun 26, 2024
Activity
[-]RTL issue with patching asyncWrapper/eventWrapper (with act()) for userEvent API in Vitest[/-][+]RTL + Vitest issue with patching asyncWrapper/eventWrapper (with act()) for userEvent APIs[/+]