标题是,如何检查组件是否已卸载?
我尝试使用component.length检查它,但它总是有长度(不是零)。
component.length
有没有办法检查组件是否已卸载?
未安装的组件应该不再是DOM表示的一部分。
因此,您应该能够在未安装的组件选择器上使用酶的exists方法:
exists
const component = wrapper.find('MyUnmountedComponent'); expect(component.exists()).toBe(false);