【发布时间】:2020-10-03 19:08:28
【问题描述】:
我正在尝试将 Jest 用于新的 CRA 项目,但在尝试使用 findByText 函数时遇到问题。我安装了:
yarn add -D jest-environment-jsdom-sixteen
然后使用react-scripts test --env=jest-environment-jsdom-sixteen 运行我的测试。如果我执行在此处阅读这些问题时遇到的解决方案,则效果很好:
- https://github.com/testing-library/dom-testing-library/issues/477
- https://github.com/testing-library/react-testing-library/issues/662
- https://github.com/testing-library/react-testing-library/issues/731
但是我也在使用 VS 代码中的 Jest 插件,并且测试没有通过它。我已经尝试在我的jest.config.js 中按照in the docs 的建议执行此操作:
module.exports = {
testEnvironment: 'jest-environment-jsdom-sixteen',
};
但还是不行。
提前致谢。
【问题讨论】:
标签: reactjs jestjs create-react-app react-testing-library