javascript - jest snapshot 使用 enzyme 打破情绪 10/babel 7

标签 javascript reactjs jestjs enzyme emotion

所以我的开 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/

相关文章:

javascript - 如何将行索引值附加到 td 的 ID

javascript - 如何让我的脚本从 30 个随机 div 中生成 12 个 - Jquery

javascript - 如何使用 React.js 将二维数组传递给 array.prototype.map()

javascript - 测试具有多个 Promise 的 Jest 方法

node.js - 如何在所有测试之前设置 DynamoDB 表并在所有测试之后将其拆除?

javascript - 使用 forEach 和 async/await,对于 Node 和 Jest 的行为不同

javascript - 一个对象可以未定义但具有已定义的属性吗? (Javascript)

javascript - 为什么javascript中的数字键总是排序到开头?

node.js - 找不到模块 : Error: Cannot resolve module 'react-addons-test-utils'

javascript - Normalizr 转换模式的麻烦