score:56

Accepted answer
expect(comp.type()).toEqual(null)

That's it!

or:

expect(comp.get(0)).toBeFalsy()

score:0

As mentioned in Benjamin Intal's solution, I tried to use myComponent.isEmptyRender(), but it was unexpectedly returning false, even though myComponent.children().length was returning 0.

The problem turned out to be that myComponent was coming from a call to .find() on another shallow-rendered component. In this situation, an extra call to .shallow() on the found child component is necessary to get isEmptyRender() to work properly:

const parentComponent = shallow(<MyParentComponent isMyChildHidden={true} />);
const childComponent = parentComponent.find('MyChildComponent');

expect(childComponent.shallow().isEmptyRender()).toBe(true);

Reference: https://github.com/enzymejs/enzyme/issues/1278

score:6

we use the following with jest-enzyme

expect(comp).toBeEmptyRender()

score:28

According to ShallowWrapper::html implementation it returns null if component instance type is null, as a result of render.

expect(comp.html()).toBeNull();

score:73

ShallowWrapper has a isEmptyRender() function:

expect(comp.isEmptyRender()).toBe(true)

Related Query

More Query from same tag