我正在尝试将Jest与新的CRA项目一起使用,但是在尝试使用findByText
函数时遇到了问题。我安装了:
yarn add -D jest-environment-jsdom-sixteen
然后使用react-scripts test --env=jest-environment-jsdom-sixteen
运行我的测试。如果我在阅读以下这些问题时遇到了这种解决方案,则效果很好:
但是我也使用VS代码中的Jest插件,并且测试没有通过。我已尝试按照建议的in the docs在jest.config.js
中进行此操作:
module.exports = {
testEnvironment: 'jest-environment-jsdom-sixteen',
};
但是它仍然不起作用。
谢谢。
答案 0 :(得分:1)
Testing MutationObserver with Jest: 试试这个对我有用的类似错误:
npm i -D mutationobserver-shim
import "mutationobserver-shim";