【问题标题】:enzyme - how can I check if the component is unmounted?酶 - 我如何检查组件是否已卸载?
【发布时间】:2019-01-20 22:16:42
【问题描述】:

如题,如何检查组件是否已卸载?

我尝试使用component.length 检查它,但它总是有长度(不是零)。

有没有办法检查组件是否已卸载?

【问题讨论】:

    标签: javascript tdd enzyme


    【解决方案1】:

    未安装的组件不应再成为 DOM 表示的一部分。

    因此,您应该能够在未安装的组件选择器上使用酶的 exists 方法:

    const component = wrapper.find('MyUnmountedComponent');
    expect(component.exists()).toBe(false);
    

    【讨论】:

      猜你喜欢
      • 2016-03-23
      • 2019-12-28
      • 2017-02-07
      • 2014-11-07
      • 2015-11-06
      • 2021-01-13
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      相关资源
      最近更新 更多