Jest-dom: toBeInTheDocument error with material-ui icons

Created on 11 Sep 2020  路  2Comments  路  Source: testing-library/jest-dom


Hello, I think this is a bug but I'm not sure because I'm not an expert on your great lib !
Everything you need is in codesandbox reproduction.

What happened:

Error on test expect(wrapper.find(CloseIcon)).toBeInTheDocument();
But with classic expect(wrapper.find(CloseIcon)).toHaveLength(1); it works... This is why I think it's a bug.

Reproduction:

https://codesandbox.io/s/morning-river-ymv5b?file=/src/App.test.js

Problem description:

received value must be an HTMLElement or an SVGElement.
Received has type: object
Received has value: {}

Most helpful comment

Enzyme does not return actual DOM elements but custom objects. This library does not support wrappers from enzyme.

All 2 comments

Enzyme does not return actual DOM elements but custom objects. This library does not support wrappers from enzyme.

Note that this is designed to work with React Testing Library which uses actual DOM elements. If you want to keep Enzyme, you may want to use Enzyme-specific matchers or get the DOM elements from Enzyme before using them with jest-dom.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jsphstls picture jsphstls  路  4Comments

gnapse picture gnapse  路  3Comments

lukaszfiszer picture lukaszfiszer  路  6Comments

tom-sherman picture tom-sherman  路  5Comments

maltebaer picture maltebaer  路  6Comments