创建快照时,Jest/Enzyme ShallowWrapper为空 [英] Jest/Enzyme ShallowWrapper is empty when creating Snapshot

查看:496
本文介绍了创建快照时,Jest/Enzyme ShallowWrapper为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在为我的Item组件编写一个测试,我尝试呈现ItemCard组件,然后使用该包装器创建快照,但是它返回一个空的ShallowWrapper {}

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 ShallowWrapper {}

请参阅代码以获取更多信息:

Please see the code for more info:

Item.test.js

Item.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 {}`;

据我所知ShallowWrapper应该包含一些内容而不是空的.

As far as I know the ShallowWrapper should have some content in it instead of being empty..

有人可以告诉我我在做什么错吗?

Can someone tell me what am I doing wrong here?

谢谢

推荐答案

更新到jest@24.0.0后,我遇到了同样的问题 我暂时已经恢复到以前的版本jest@23.6.0,直到我发现发生了什么变化.如果发现更改,请在此处发布.

I faced the same issue after updating to jest@24.0.0 I have reverted to the previous version jest@23.6.0 for the time being till i figure out what has changed. If you find what has changed, do post it here.

这篇关于创建快照时,Jest/Enzyme ShallowWrapper为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆