Skip to content
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

Unmount enzyme components after test execution #3255

Merged
merged 1 commit into from
Apr 6, 2020

Conversation

chandlerprall
Copy link
Contributor

Summary

Turns out enzyme does not attempt to unmount or cleanup components after executing. It makes sense, but is unfortunate. The impact to us has mostly been through the MutationObserver polyfill singleton yelling about too many listeners and possible memory leak. Turns out there was a memory leak.

  • intercepts calls to mount and stores a reference to the returned component
  • added a global afterEach to unmount any still-mounted components
  • bumped un-bumped? cratered the MutationObserver polyfill's setMaxListeners back to a reasonable number
  • modified EuiDroppable's test to reset the react-beautiful-dnd context counter
    • the snapshots were already affected by the global unmounting
    • its individual snapshots are no longer reliant on order or existence of execution

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile
- [ ] Checked in IE11 and Firefox
- [ ] Props have proper autodocs
- [ ] Added documentation examples

  • Added or updated jest tests
    - [ ] Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
    - [ ] A changelog entry exists and is marked appropriately


test('sets `cloneItems` on proprietary context', () => {
const handler = jest.fn();
const component = mount(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to move these mounts into the test themselves, otherwise the auto-unmounting was executing before the assertions

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3255/

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding this!

Confirmed MaxListenersExceededWarning warning is now gone

@chandlerprall chandlerprall merged commit 5a83811 into elastic:master Apr 6, 2020
@chandlerprall chandlerprall deleted the cleanup-enzyme-mounts branch April 6, 2020 22:01
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants