变异观察者不是构造函数(笑话)

时间:2020-10-03 19:08:28

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

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

yarn add -D jest-environment-jsdom-sixteen

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

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

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

但是它仍然不起作用。

谢谢。

1 个答案:

答案 0 :(得分:1)

Testing MutationObserver with Jest: 试试这个对我有用的类似错误:

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