testing-library / testing-library/testing-library-docs
Cannot use `dont-cleanup-after-each` in browser
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 479
- Forks
- 740
- PR merge metrics
- No merged PRs in 30d
Description
@testing-library/reactversion: 13.3.0- Testing Framework and version: Storybook 6.5.9
- DOM Environment: Browser
Relevant code or config:
import '@testing-library/react/dont-cleanup-after-each';
What you did:
I'm trying to update to react 18, but am getting errors about act not being available in production builds of react. So, I tried setting globalThis.IS_REACT_ACT_ENVIRONMENT = false, but found that this library automatically sets it to true, so to disable it I tried to import dont-cleanup-after-each as instructed in https://testing-library.com/docs/react-testing-library/setup#skipping-auto-cleanup, since https://github.com/testing-library/react-testing-library/pull/994 said to disable it the same way as cleanup.
What happened:
Uncaught ReferenceError: process is not defined
at dont-cleanup-after-each.js:1:1
This is because process does not exist in browsers, which is where I'm running RTL.
Reproduction:
Problem description:
I can't disable the use of ACT, it seems, which causes my tests to fail.
Suggested solution:
If process is not defined, you could check for import.meta.env and use that instead.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting dont-cleanup-after-each.js and the browser setup described in the issue; verify why it references process when loaded outside Node. Reproduce the failure in a browser-based test setup, then confirm that disabling cleanup and the related ACT behavior works without the ReferenceError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100