enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.96k stars 2.01k forks source link

Cannot find SVG icon via Enzyme #2146

Closed turnerhayes closed 5 years ago

turnerhayes commented 5 years ago

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

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

ljharb commented 5 years ago

Can you please fill out the entire issue template?

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

turnerhayes commented 5 years ago

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

oliviertassinari commented 5 years ago

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

ljharb commented 5 years ago

Thanks, this is enough to reproduce.

turnerhayes commented 5 years ago

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

ljharb commented 5 years ago

as soon as i have time; hopefully today.

gReis89 commented 4 years ago

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 commented 4 years ago

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

oliviertassinari commented 4 years ago

Is this related to https://github.com/mui-org/material-ui/issues/15928?

ljharb commented 4 years ago

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

oliviertassinari commented 4 years ago

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

ljharb commented 4 years ago

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.