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

后端 未结 5 2005
离开以前
离开以前 2021-02-04 23:15

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

5条回答
  •  借酒劲吻你
    2021-02-05 00:02

    .contains does not expect a selector, unlike find. You can look at the length attribute of the ShallowWrapper

    expect(wrapper.find('...')).toHaveLength(0)

    I found I needed to use this syntax with Enzyme and Jest to test if a Connected Component existed in the rendered output.

提交回复
热议问题