-
Notifications
You must be signed in to change notification settings - Fork 232
Global unmountAll
functionality
#76
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
We have the same problem. When this library moved to react-test-renderer, the cleanup function was removed. This is fine when you are just testing rendering, but a big part of hooks is side effects. There doesn't seem to be a great way to have a global unmount and we are currently stuck on v0.4.1. |
@userbq201 if you are trying to report a bug, you should probably open a different ticket. This ticket is not about a bug, just about how to best use what features are available. |
Hey, sorry I've been a bit quiet. I've been moving interstate so my spare time has been a bit light on, but I'm here now. To be honest, an If anyone wants to implement something like that and submit a PR, I think it would be a useful addition to the library. It would need to track each rendered hooks and unmount all of them, unlike this snippet which only unmounts the last rendered hook, but that should not be too difficult. |
Just wondering if this should be called |
I like how jest has the different levels of |
A quick workaround for me was to create a small wrapper and use only this for the tests // './renderHook.js';
import {renderHook} from '@testing-library/react-hooks';
let unmounts = [];
export const cleanup = () => {
unmounts.forEach(unmount => unmount());
unmounts = [];
};
export default (...args) => {
const rendered = renderHook(...args);
unmounts = [...unmounts, rendered.unmount];
return rendered;
}; import {cleanup as cleanupHooks} from './renderHook';
afterEach(cleanupHooks); |
I'd be happy with more-or-less the same approach to be done as a PR ( |
I have an effect that uses
setInterval
. In order for my tests to work right, I need tounmount
so the interval gets knocked away.I have code like this:
Is this the expected paradigm? Is this an example that would be good for docs? Is this horrible?
The text was updated successfully, but these errors were encountered: