Jest/Enzyme ShallowWrapper is empty when creating Snapshot

前端 未结 8 839
醉话见心
醉话见心 2020-12-28 15:25

So I\'m writing a test for my Item component and I tried to render the ItemCard component and then use that wrapper to create a snapshot but it returns an empty

相关标签:
8条回答
  • 2020-12-28 16:20

    For jest v24 you need to use snapshot serializer like https://github.com/adriantoine/enzyme-to-json

    source: https://github.com/facebook/jest/issues/7802

    0 讨论(0)
  • 2020-12-28 16:21

    use debug() method after the wrapper

      it('renders and matches the snapshot', () => {
    const wrapper = shallow(<ItemCard me item={fakeItem} showButtons />);
    
    // console.log(wrapper.debug());
    expect(wrapper.debug()).toMatchSnapshot(); });
    
    0 讨论(0)
提交回复
热议问题