[Feature Request] Mount tracking
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 19.8k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem? Please describe.
When using full DOM rendering, I'd like to be able to orchestrate calling unmount via an afterEach-style hook, rather than having to call unmount in each test.
Note When unmount was not called at all, I experienced memory leaks when working with large test suites.
Describe the solution you'd like
Obviously, enzyme does not assume a specific test environment. I think the right solution here is for enzyme to provide some form of mount-tracking with an unmountAll function.
Describe alternatives you've considered
Currently, we expose a library which wraps enzyme's mount function, tracking the ReactWrapper instances, and then calling unmount on them via our library.
This solution is problematic, as most developers are familiar with import {mount} from 'ezyme';, and we'd end up needing a lint rule to prevent that. Also, I feel that this solution makes sense to be included in enzyme itself so that others can benefit from better handling of memory leaks.
Additional context
Some implementation considerations:
-
if someone calls
unmountmanually, we probably want to delete any global references tot he underlying wrapper, so that the JS engine can properly garbage-collect it. It also doesn't make sense to callunmountmultiple times anyhow. -
Many applications will use something like mocked timers int heir testing suites. We'll need to consider the case where these utilities are referenced via a component's
componentWillUnmounthook. In such a case, if the mock is removed after the test and then we try to run a globalunmountAllhook on that component, we may encounter errors from the mocking utility. One way to handle this is via documentation, suggesting the package consumer to manually callunmounton those wrappers before restoring any mocked utilities.
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 locating the full DOM mount API and ReactWrapper lifecycle, then trace how unmount is currently handled. Define how mounted wrappers are tracked, removed after manual unmount, and released by an unmountAll function. Check behavior with mocked timers and document the required cleanup order for componentWillUnmount hooks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100