Jest - how to test if a component does not exist?

How do I check if a component is not present, i.e. that a specific component has not been rendered?


Solution 1:

.contains receives a React Node or array of Nodes as an argument. Instead, use .find:

expect(wrapper.find('selector').exists()).toBeTruthy()

Solution 2:

You can use enzymes contains to check if the component was rendered:

expect(component.contains(<ComponentName />)).toBe(false)