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 regression in 3.4.0 #1880

Closed
2 of 13 tasks
ZebraFlesh opened this issue Oct 26, 2018 · 4 comments
Closed
2 of 13 tasks

unmount regression in 3.4.0 #1880

ZebraFlesh opened this issue Oct 26, 2018 · 4 comments

Comments

@ZebraFlesh
Copy link

Current behavior

Using enzyme 3.3.0, it is possible to do the following:

const wrapper = mount(<MyComponent />);
expect(wrapper.find('.my-component')).to.exist;
wrapper.unmount();
expect(wrapper.find('.my-component')).to.not.exist;

When upgrading to 3.4.0, the last line now fails with Error: Method “name” is only meant to be run on a single node. 0 found instead. Indeed, adding console.log(wrapper.name()) after the unmount call results in the same error.

Expected behavior

Unmounted wrapper continues to function as expected in 3.3.0

Your environment

API

  • shallow
  • mount
  • render

Version

library version
enzyme 3.4.0 (also applies to 3.7.0)
react 16.4.1
react-dom 16.4.1
react-test-renderer 16.2.0
adapter (below) 1.6.0

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )
@ljharb
Copy link
Member

ljharb commented Oct 26, 2018

I'm a little confused; what calls .name()? It might be your to.exist matcher; what happens if you use something more explicit?

@ZebraFlesh
Copy link
Author

I'm using chai-enzyme for that. Digging into that code, it seems like that may be the source of the issue: chai-enzyme is checking that the enzyme wrapper.length > 0, failing, and then trying to report it (likely using the name). However, this a change that I noticed during debugging:

  • v3.3.0: mounted enzyme wrapper has length 1 after unmount
  • v3.4.0: mounted enzyme wrapper has length 0 after unmount

So is that an enzyme regression, an intended change, and/or an implementation detail which chai-enzyme should perhaps not be leveraging?

@ljharb
Copy link
Member

ljharb commented Oct 26, 2018

It looks like the change was made in #1498 - specifically, this line was removed, which (imo incorrectly) forced the length to be 1.

In other words, I think it's an intentional bug fix - and as far as chai-enzyme goes, i think they were unintentionally relying on the erroneous behavior to have .name() work.

Could you rewrite your test case to use .name() and not chai-enzyme, with what happens in 3.3 vs 3.4? We may still be able to fix that particular method, which would unbreak your chai-enzyme use case.

@ljharb
Copy link
Member

ljharb commented Feb 26, 2019

@ZebraFlesh closing; happy to reopen if you can make the change in my previous comment and there's something we can fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants