-
Notifications
You must be signed in to change notification settings - Fork 721
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
Cannot use dont-cleanup-after-each
in browser
#1131
Comments
We currently don't support testing production builds of React.
You can also import from I'm leaving this open for suggestions but I don't see how we would support testing production builds since that's mostly a documentation effort. You're better off using an e2e testing framework in a real browser if you want to test production builds. |
Thanks, I am in fact testing in a real browser using storybook's testing tools. I tried importing from pure, with no luck, so I think this is not the issue I thought it was at first. In fact I found that if I use @storybook/testing-library, which wraps and instruments the testing-library methods, this issue is resolved. I don't understand why though, yet. Feel free to close this issue, since it sounds like you don't expect the library to be used in production builds. But I think that ideally testing-library should work in browsers, not just inside jest or when using webpack. |
These are two different things. The library can absolutely be used in a browser. I've been doing that for years. What is currently unsolved is testing with a React production build. That build can run in a browser, Node or any other JS runtime. |
I guess my point was that https://github.com/testing-library/react-testing-library/blob/main/dont-cleanup-after-each.js cannot run in a browser, and this check is also broken in the browser: https://github.com/testing-library/react-testing-library/blob/c80809a956b0b9f3289c4a6fa8b5e8cc72d6ef6d/src/index.js#L9 since |
You don't need it in a browser. |
Hm isn't this just a documentation issue? Auto-cleanup should be disabled in browsers anyway since |
If |
Yeah let's move this to documentation that you should use a bundler. That solves most use cases and once we think the ecosystem is ready for |
@testing-library/react
version: 13.3.0Relevant code or config:
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 settingglobalThis.IS_REACT_ACT_ENVIRONMENT = false
, but found that this library automatically sets it to true, so to disable it I tried to importdont-cleanup-after-each
as instructed in https://testing-library.com/docs/react-testing-library/setup#skipping-auto-cleanup, since testing-library/react-testing-library#994 said to disable it the same way as cleanup.What happened:
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 forimport.meta.env
and use that instead.The text was updated successfully, but these errors were encountered: