Skip to content
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

RTL + Vitest issue with patching asyncWrapper/eventWrapper (with act()) for userEvent APIs #1338

Open
millerized opened this issue Jun 26, 2024 · 0 comments · May be fixed by #1343
Open

RTL + Vitest issue with patching asyncWrapper/eventWrapper (with act()) for userEvent APIs #1338

millerized opened this issue Jun 26, 2024 · 0 comments · May be fixed by #1343

Comments

@millerized
Copy link

millerized commented Jun 26, 2024

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-library/dom": "10.2.0",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.2",

"jsdom": "^24.0.0",
"vite": "^5.3.1",
"vitest": "^1.6.0",
"vitest-dom": "^0.1.1"

DOM Environment: JSDOM

Relevant code or config:

See reproduction section for code.

What you did:

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 */

Reproduction:

Please see this stack blitz repro: https://stackblitz.com/edit/vitejs-vite-x8atqu?file=package.json%3AL34,src%2Fselect.spec.jsx&terminal=dev

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.

@millerized millerized 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 Jun 26, 2024
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

Successfully merging a pull request may close this issue.

1 participant