Search code examples
reactjsenzymechai-enzyme

Enzyme Shallow() returns an element that doesn't work with selectors correctly


I expected this to work but it doesn't:

const element = shallow(<SomeComponentClass />);
element.is(SomeComponentClass); // === false, why?

I get false although I was expecting it to return true.
Using mount() instead of shallow() returns true

Why? Thanks!


Solution

  • I opened an issue for enzyme about this and it seems like shallow doesn't return the component class but the rendered dim element. https://github.com/airbnb/enzyme/issues/768#issuecomment-272125380

    So the false is intentional. Mount should also return false, actually.