![](/img/trans.png)
[英]When importing a module from node_modules that uses route based lazy loading in create-react-app, should code splitting work in the same way?
[英]How to exclude node_modules from create-react-app testing?
我想使用 jest 测试我的 create-react-app。
node_modules 之一有测试错误,
但我不希望 jest 使用 node_modules 文件夹。
在文档中,我找到了配置属性“collectCoverageFrom”并尝试在我的 package.json 中使用它:
....
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom ",
"eject": "react-scripts eject"
},
"jest": {
"collectCoverageFrom": [
"!/node_modules/*"
]
}
但什么都没有改变。
没有什么可以覆盖的。
您的组件之一是使用react-mic
包通过window.AudioContext
提供对音频的访问。
你有不同的方法来解决它。
您可以模拟window.AudioContext
。 真的很难实现。 我真的不建议你这样做。
您可以模拟react-mic
模块。 这比#1 更容易实现,但仍然相当困难。
您可以在测试中依赖shallow()
。 因此,您根本不需要模拟与音频相关的任何内容。 我想建议你这样做。
已经是这样了。 Jest 忽略node_modules
。 你看到的只是一个堆栈跟踪。 仔细检查您的测试代码,那里发生了错误。
在配置 jest 时尝试使用testPathIgnorePatterns
:
"jest": {
...
"testPathIgnorePatterns": [
"<rootDir>/(build|docs|node_modules)/"
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.