创建快照时 Jest/Enzyme ShallowWrapper 为空 [英] Jest/Enzyme ShallowWrapper is empty when creating Snapshot
问题描述
所以我正在为我的 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...
推荐答案
我更新到 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屋!