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

Cannot find SVG icon via Enzyme #2146

Closed
2 of 13 tasks
turnerhayes opened this issue May 30, 2019 · 12 comments
Closed
2 of 13 tasks

Cannot find SVG icon via Enzyme #2146

turnerhayes opened this issue May 30, 2019 · 12 comments

Comments

@turnerhayes
Copy link

turnerhayes commented May 30, 2019

I filed this bug with Material UI, but they seem to think it's an Enzyme bug. One of the MUI team members there commented that

It's likely an issue with composing memo(forwardRef()).

Current behavior

Enzyme doesn't even seem to recognize that the icon is of the type of the icon; that is,

import EditIcon from '@material-ui/icons/Edit';

console.log(mount(<EditIcon />).is(EditIcon));

displays false. As a result, if I have an IconButton that contains <EditIcon/>, Enzyme doesn't find it.

See https://codesandbox.io/s/fervent-bash-5ys2g

Expected behavior

mount(<ComponentContainingMUIIcon />).find(MUIIcon) should return a wrapper for the icon.

Your environment

API

  • shallow
  • mount
  • render

Version

library version
enzyme 3.9.0
react 16.8.6
react-dom 16.8.6
react-test-renderer N/A
adapter (below) 1.13.2

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 May 30, 2019

Can you please fill out the entire issue template?

From the linked issue, it looks like an interaction between memo and forwardRef.

@turnerhayes
Copy link
Author

Done! Let me know if there's any more information that would be useful.

@oliviertassinari
Copy link

It would have been even better without Material-UI as a dependency of the codesandbox.

@ljharb
Copy link
Member

ljharb commented Jun 1, 2019

Thanks, this is enough to reproduce.

ljharb added a commit that referenced this issue Jun 1, 2019
Note: although this is an important `memo` bugfix, this *might* be a breaking change (note the `find` test change from 1 to 2) but since it should be exceedingly rare for tests to have a reference to both the memoized and unmemoized form of a component, my hope is that it won’t impact anybody.

Fixes #2146.
@ljharb ljharb closed this as completed in ddb0627 Jun 2, 2019
@turnerhayes
Copy link
Author

Great! Thanks for the quick turnaround! When will this be published on NPM?

@ljharb
Copy link
Member

ljharb commented Jun 3, 2019

as soon as i have time; hopefully today.

ljharb added a commit that referenced this issue Jun 3, 2019
 - [New] add `matchesElementType` (supports fix for #2146)
 - [Fix] `selectors`: unwrap `memo` elements - in both directions (#2146)
@gReis89
Copy link

gReis89 commented Nov 27, 2019

it stoped working again after material-ui/core 4.7.0 update(works on 4.6.1):
https://codesandbox.io/s/blissful-mendeleev-3vj5l

@ljharb
Copy link
Member

ljharb commented Nov 27, 2019

@gReis89 sounds like they had a breaking change in a minor version; i'd file an issue.

@oliviertassinari
Copy link

Is this related to mui/material-ui#15928?

@ljharb
Copy link
Member

ljharb commented Nov 27, 2019

@oliviertassinari it may be a similar cause; but that was the cause of the OP. The latest report is something new.

@oliviertassinari
Copy link

It seems different, indeed. What could explain this new behavior?

@ljharb
Copy link
Member

ljharb commented Nov 27, 2019

Perhaps a change in display name, or they changed the number of HOC wrappers on a component? Not really sure, I'm not familiar with material UI.

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

4 participants