【发布时间】:2021-05-29 23:32:14
【问题描述】:
我在 React 的一个组件中配置了一项服务,但我遇到了 jest 和测试库的问题,应用程序正在运行,但测试被阻塞。
import { appSetupConfig } from '.../myapp'
import theConfig from '.../config'
useEffect(() => {
const allowAppInstance = appSetupConfig();
allowAppInstance.get(theConfig).then((value) => {
if (value.something) {
Do Something;
}
...the rest of code
}, []);
这个 theConfig 是一个包含对象的外部文件。 这是错误:
TypeError: Cannot read property 'get' of undefined
37 | const allowAppInstance = appSetupConfig();
38 |
> 39 | allowAppInstance.get(theConfig).then((value) => {
有没有办法在 jest 的 setup.js 中模拟这个 get? 我不一定需要测试这个项目,但没有它我就无法继续。
【问题讨论】:
标签: javascript reactjs unit-testing jestjs react-testing-library