-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Have render call cleanup #428
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
Comments
If |
I think the suggestion is to call |
Yes, I meant calling |
I was wondering how this would affect the rerendering of components? |
I guess we'd need to make sure that calling |
🤔 I like the idea of reducing the amount of setup required...
This might make sense at a higher level of abstraction like the |
Let’s say a component has a bug where unmounting throws an error (the effect cleanup is bad, eg). Then this feature would make the next test fail, and debugging would be a pain. Not sure if this is worth the short term gain, tbh. The ‘fix’ should be figuring out how to automate cleanup. (As an example, why not “import ‘cleanup-after-each’” by default on importing rtl?) |
I've considered that. If we made |
👆 |
The more I think about it, the more I think this makes sense. I'm totally open to seeing a PR for this. |
This seems like a big deal though. |
It is a big deal. What Sunil suggested and what I want is for |
👍 misread what "this" meant in "this makes sense" |
One additional thing to confirm is that this works if you have a custom test utils file that imports and re-exports from RTL. |
Yes, definitely would work with that |
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
Alright, I feel really great about this. Made #430. |
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
I'm thinking this'll happen soon. Will require a major version bump though 😬 |
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428 BREAKING CHANGE: If your tests were not isolated before (and you referenced the same component between tests) then this change will break your tests. You should [keep your tests isolated](https://kentcdodds.com/blog/test-isolation-with-react), but if you're unable/unwilling to do that right away, then you can either run your tests with the environment variable `RTL_SKIP_AUTO_CLEANUP` set to `true` or import `@testing-library/react/pure` instead of `@testing-library/react`.
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428
You can disable this with the RTL_SKIP_CLEANUP environment variable if you so choose, but it's recommended to have cleanup work this way. Closes #428 BREAKING CHANGE: If your tests were not isolated before (and you referenced the same component between tests) then this change will break your tests. You should [keep your tests isolated](https://kentcdodds.com/blog/test-isolation-with-react), but if you're unable/unwilling to do that right away, then you can either run your tests with the environment variable `RTL_SKIP_AUTO_CLEANUP` set to `true` or import `@testing-library/react/pure` instead of `@testing-library/react`.
🎉 This issue has been resolved in version 9.0.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Describe the feature you'd like:
Right now we have to call
cleanup
before each test. This tends to be confusing for beginners especially if they come from other libraries (Enzyme) that do not need this step. It would be good ifrender
could callcleanup
automatically.Suggested implementation:
I didn't dig into the code too much but it should be as easy as having
render
callcleanup
as the first thing it does.Describe alternatives you've considered:
I'm trying to think about a use-case where you might want to run two
render
s in the same test or where you might want to manually runcleanup
—which would invalidate this idea—but can't come up with anything.Teachability, Documentation, Adoption, Migration Strategy:
We would have to remove the documentation about
cleanup
. Potentially we would have to introduce a breaking change.The text was updated successfully, but these errors were encountered: