@material-ui/icons 4.11.2 no longer has unique displayNames on icons according to enzyme .name()
See original GitHub issuePrior to 4.11.2 when I used an enzyme wrapper to get the name() of an icon component, it returned the name of each component properly (i.e. the Error icon return ErrorIcon, the Add icon returned AddIcon, etc.). Now all icons return the same name: Memo([object Object])
See the test file in an example code sandbox
- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
The name of all icons in 4.11.2 is Memo([object Object])
Expected Behavior 🤔
The name of every icon in 4.11.2 is the same as they were in 4.9.1
Steps to Reproduce 🕹
Steps:
- Using this codesandbox instance, see the tests working properly with 4.9.1
- Using this codesandbox instance, see the same tests failing with 4.11.2
Context 🔦
My tests for my applications are checking to see if I have the proper icon being rendered using the name() function on an enzyme wrapper, with this upgrade my tests are breaking.
Your Environment 🌎
An example of a functioning code is found in this code sandbox with @material-ui/icons@4.9.1: https://codesandbox.io/s/brave-galois-hm1mf
An example of the breaking code is found in this code sandbox with @material-ui/icons@4.11.2: https://codesandbox.io/s/nostalgic-brahmagupta-djl98
| Tech | Version |
|---|---|
| Material-UI | v4.11.2 |
| React | 16.14.0 |
| Browser | N/A |
| TypeScript | N/A |
| etc. |
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (8 by maintainers)

Top Related StackOverflow Question
I don’t know how enzyme’s name() behaves these days with forwardRef and memo. Especially across various versions of React.
The usual advise still stands: Don’t use enzyme unless you’re following a testing approach that doesn’t rely on component internals. Either by following the approach explained in https://testing-library.com/docs/react-testing-library/intro or actually using
@testing-library/react.Other than that I recommend rolling back to the previous version of
@material-ui/icons.From now on, I test Material UI Icons with the Icon Component directly, not with name anymore, like:
Also I’m using NextJS. Guide: https://medium.com/fredwong-it/react-enzyme-expect-material-ui-icon-memo-object-object-a988c92f6d17