代码之家  ›  专栏  ›  技术社区  ›  dragi

创建快照时,jest/酶浅包装为空

  •  0
  • dragi  · 技术社区  · 6 年前

    因此,我正在为我的项组件编写测试,并尝试呈现 ItemCard 组件,然后使用该包装器创建快照,但它返回空的 ShallowWrapper {}

    更多信息请参见代码:

    ITE.Test.JS

    import { shallow } from 'enzyme';
    import { ItemCard } from '../Item';
    
    const fakeItem = {
      id: 'aksnfj23',
      title: 'Fake Coat',
      price: '40000',
      description: 'This is suuuper fake...',
      image: 'fakecoat.jpg',
      largeImage: 'largefakecoat.jpg',
    };
    
    describe('<ItemCard/>', () => {
      it('renders and matches the snapshot', () => {
        const wrapper = shallow(<ItemCard me item={fakeItem} showButtons />);
    
        // console.log(wrapper.debug());
        expect(wrapper).toMatchSnapshot();
      });
    });
    

    它创建的捕捉:

    // Jest Snapshot v1
    
    exports[`<ItemCard/> renders and matches the snapshot 1`] = `ShallowWrapper {}`;
    

    据我所知,浅包装纸应该有一些内容,而不是空的。

    有人能告诉我我在这里做错了什么吗?

    谢谢

    2 回复  |  直到 6 年前
        1
  •  1
  •   user2564429    6 年前

    在更新到jest@24.0.0之后,我遇到了同样的问题。 我暂时恢复到以前的版本jest@23.6.0,直到我知道发生了什么变化。如果你发现有什么变化,就把它贴在这里。

        2
  •  1
  •   Titenis    6 年前