As the title is, How can I check if a component is unmounted?
I tried to check it using component.length
, but it always has length(not zero).
Is there a way to check if a component unmounted?
Answer
An unmounted component should be no more part of the DOM representation.
Therefore you should be able to use enzyme’s exists
method on your unmounted component selector:
const component = wrapper.find('MyUnmountedComponent'); expect(component.exists()).toBe(false);