所以我正在为我的Item组件编写一个测试,我尝试渲染ItemCard
组件,然后使用该包装器创建快照,但它返回一个空的ShallowWrapper {}
请参阅更多代码信息:
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应该在其中包含一些内容,而不是为空...。
据我所知,ShallowWrapper应该在其中包含一些内容,而不是为空...
mount
而不是shallow
会让你更开心。 - Alejandroshallow
更改为mount
并转换为函数组件后,测试通过了,但我不知道原因。 - Mrmld Sky