Comments (6)
@kvet ,
That's an interesting proposal! I'll look into it. It might be difficult to implement cleanupReactHooks(forWrapper)
, since the library has no knowledge of components on Enzyme wrappers. But I can certainly add a method for firing all cleaning up functions.
from jest-react-hooks-shallow.
Hi @kvet ,
Thank you for submitting the issue. Unfortunately, as the FAQ says the library has no way of trigger cleanup functions when a component unmounts. The cleanup functions are only called before invoking the same effect again.
from jest-react-hooks-shallow.
Hi @mikeborozdin ,
I didn't notice this. However, maybe it is possible to at least export some function to perform a manual cleanup?
from jest-react-hooks-shallow.
Hi @kvet ,
Do you have an example on how the code doing that would look like? What are you trying to achieve?
If you have to invoke a cleanup manually in a test, is there much point in testing it?
from jest-react-hooks-shallow.
In my scenario, I want to test cleanup function on unmount. So, that unmount is already done with wrapper.unmount()
method. And it should not be a problem for those who really want to test this, call an additional method here like cleanupReactHooks()
.
This of course can cause problems with multiple components testing on the one test. But I guess we can provide wrapper instance to that method in order to call hooks cleanups for specific component. Something like cleanupReactHooks(forWrapper)
.
from jest-react-hooks-shallow.
👍 for this
In my case, I'm trying to test an event listener attached to document
in an effect. Without cleanup on unmount, every test case will add another listener to document
which will never be cleaned up. Makes toHaveBeenCalledTimes()
really unpredictable.
from jest-react-hooks-shallow.
Related Issues (20)
- script random number in range
- beforeEach is not defined HOT 10
- enableHooks not sufficient if jest config contains "resetMocks: true" HOT 11
- beforeEach is not defined HOT 1
- withHooks and withoutHooks do not support async tests / promises HOT 12
- Clash with mocking React to work around useRef problems HOT 2
- Acknowledgement HOT 1
- How to run useEffect cleanup - Help HOT 1
- useEffect run cleanup function in wrong trigger HOT 1
- Consider back documenting to enzyme's open issue HOT 1
- Added plugin to package.json HOT 1
- Doesn't seem to play well with ts-jest HOT 1
- Incompatible with Jest 26+ HOT 7
- Possible way to get around mount issues
- Npm7 & React 17 peer dependency error HOT 1
- dontMockByDefault not working? HOT 2
- Not working correctly with beforeAll
- work with jest 27? HOT 2
- Support for storybook HOT 1
- Support for React 18 ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-react-hooks-shallow.