【问题标题】:Mutation observer is not a constructor (Jest)变异观察者不是构造函数(开玩笑)
【发布时间】:2020-10-03 19:08:28
【问题描述】:

我正在尝试将 Jest 用于新的 CRA 项目,但在尝试使用 findByText 函数时遇到问题。我安装了:

yarn add -D jest-environment-jsdom-sixteen

然后使用react-scripts test --env=jest-environment-jsdom-sixteen 运行我的测试。如果我执行在此处阅读这些问题时遇到的解决方案,则效果很好:

但是我也在使用 VS 代码中的 Jest 插件,并且测试没有通过它。我已经尝试在我的jest.config.js 中按照in the docs 的建议执行此操作:

module.exports = {
  testEnvironment: 'jest-environment-jsdom-sixteen',
};

但还是不行。

提前致谢。

【问题讨论】:

    标签: reactjs jestjs create-react-app react-testing-library


    【解决方案1】:

    Testing MutationObserver with Jest: 试试这个,它对我有用,但出现了类似的错误:

    1. npm i -D mutationobserver-shim
    2. import "mutationobserver-shim"; 在 setupTests.js 中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-26
      • 2020-02-24
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      相关资源
      最近更新 更多