所以我的开 Jest 快照可以正常工作,使用 babel 6/emotion 9 在快照中生成 css 和 html 但是我需要更新到 babel 7 和 emotion 10 但是我的 enzyme 快照测试不再有效。代码编译并在更新所需代码后工作正常,只是测试被破坏(迁移文档中没有显示与测试设置更新相关的任何内容)。
test('renders properly', () => {
// this works generating the correct css / html snapshot output
expect(renderer.create(<component.Template>test</component.Template>).toJSON()).toMatchSnapshot();
//this does not
const wrapper = shallow(<component.Template>test</component.Template>);
expect(toJson(wrapper)).toMatchSnapshot();
});
enzyme 版本生成此输出:
exports[`renders properly 1`] = `
<ContextConsumer>
<Component />
</ContextConsumer>
`;
我尝试添加情绪序列化程序,方法是将其添加到 jest 配置中的 snapshotSerializers
并手动将其添加到 setupFilesAfterEnv
脚本中。
有人知道为什么我会得到这个输出吗?
最佳答案
如果你已经正确配置了所有的东西就可以了
test('renders properly', () => {
const wrapper = shallow(<component.Template>test</component.Template>);
expect(wrapper).toMatchSnapshot();
});
这应该按预期工作。
关于javascript - jest snapshot 使用 enzyme 打破情绪 10/babel 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54982111/