React enzyme — expect material-ui icon Memo([object Object])

Fred Wong
fredwong-it
Published in
1 min readJan 21, 2021

This is an interesting story after I upgrade the @material-ui/core and @material-ui/icons to v4.11.1 recently. Some of the test are failing and I need to fix all of them.

One of the errors is like this.

expect(icon.name()).toContain('CheckCircle')Expected substring: "CheckCircle"
Received string: "Memo([object Object])"

Here we find the material-ui icon by class and verify with the name of the icon/element.

It seems to be a known issue that all material-ui icon return name like “Memo([object Object])” now, and I can’t find any solution on the internet and start to feel frustrated, and plan to comment the line temporary.

Then I play around it and start to try finding icon by this and it works.

import { Warning, CheckCircle, Error } from '@material-ui/icons'const icon = wrapper.find(CheckCircle)
expect(icon.exists()).toEqual(true)

Therefore, giving me the idea, and I find out the solution. 🎉

import { Warning, CheckCircle, Error } from '@material-ui/icons'expect(icon.name()).toContain(CheckCircle)

--

--