question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@material-ui/icons 4.11.2 no longer has unique displayNames on icons according to enzyme .name()

See original GitHub issue

Prior 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:

  1. Using this codesandbox instance, see the tests working properly with 4.9.1
  2. 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:closed
  • Created 3 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
eps1loncommented, Dec 4, 2020

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.

0reactions
KeitelDOGcommented, May 2, 2021

From now on, I test Material UI Icons with the Icon Component directly, not with name anymore, like:

import SearchIcon from '@material-ui/icons/Search';

// ...

  it('should render an Icon for search', () => {
    expect(wrapper.find(SearchIcon)).toHaveLength(1);
  });

Also I’m using NextJS. Guide: https://medium.com/fredwong-it/react-enzyme-expect-material-ui-icon-memo-object-object-a988c92f6d17

Read more comments on GitHub >

github_iconTop Results From Across the Web

material-ui/icons 4.11.2 no longer has unique displayNames ...
My tests for my applications are checking to see if I have the proper icon being rendered using the name() function on an...
Read more >
material-ui/icons/CHANGELOG.md - UNPKG
Each warning comes with a simple message that explains how to handle the deprecation. If no warnings are reported in the console, you...
Read more >
@material-ui/icons - npm
This package provides the Google Material icons packaged as a set of React components. Installation. Install the package in your project ...
Read more >
Issue with Material UI Icons npm installation - Stack Overflow
This allowed me to install the MUI Icons package without any error, however, I faced numerous errors when I tried to use the...
Read more >
Material Icon Theme - Visual Studio Marketplace
Material Icon Theme. Get the Material Design icons into your VS Code. Version Rating Installs Downloads. Sponsored by. File icons.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found