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

后端 未结 5 2011
离开以前
离开以前 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:12

    Providing a slightly updated answer based on the documentation for enzyme-matchers's toExist. This will require you to install the enzyme-matchers package.

    function Fixture() {
      return (
        
    ); } const wrapper = mount(); // mount/render/shallow when applicable expect(wrapper.find('span')).toExist(); expect(wrapper.find('ul')).not.toExist();

提交回复
热议问题