Javascript Jest快照为每个测试文件返回相同的代码
我正在运行jest酶测试,带有快照。快照文件生成正确,但其内容基本上是:Javascript Jest快照为每个测试文件返回相同的代码,javascript,reactjs,jestjs,enzyme,Javascript,Reactjs,Jestjs,Enzyme,我正在运行jest酶测试,带有快照。快照文件生成正确,但其内容基本上是: // Jest Snapshot v1, https;//link exports[`Component1 should match snapshot 1`] = `ReactWrapper {}`; ^^^^^^^^ <-- only component name is changing //Jest快照v1,https//链接 导出[`Component1应与快照1`]匹配=`ReactWra
// Jest Snapshot v1, https;//link
exports[`Component1 should match snapshot 1`] = `ReactWrapper {}`;
^^^^^^^^ <-- only component name is changing
//Jest快照v1,https//链接
导出[`Component1应与快照1`]匹配=`ReactWrapper{}`;
^^^^^^^^我正在查看自己的测试,似乎需要enzymetojson
包来使用Jest创建有用的快照。这将序列化您的数据以供Jest使用。请在呈现组件以进行测试的位置添加代码。@jmargolisvt使用shallow
而不是mount
@jmargolisvt添加了测试,除了ReactWrapper
到shallowrapper
中之外,没有任何更改。这似乎是相关的:我正在查看自己的测试,它是似乎需要Ezyme to json包来使用Jest创建有用的快照。
it('should match snapshot', () => {
const component = mount(<Component1 />);
expect(component).toMatchSnapshot();
});