我有一个外部应用程序的设置并在 const 中启动它,然后将它放在const allowAppInstance appConfig的配置中
export const setupRemote = () => {
if (isRemoteAvailable) {
try {
...
const allowAppInstance = SetupConfig.start(remoteInstance);
return {
allowAppInstance,
};
} catch (e) {
console.error(e);
}
}
};
我在这里导出
export const appSetupConfig = () => setupRemote().allowAppInstance;
在组件中,我得到了这个设置并将它放在一个 const
import { appSetupConfig } from '.../myapp'
useEffect(() => {
const allowAppInstance = appSetupConfig();
...the rest of code
}, []);
该应用程序有效,但是当我运行测试时,开玩笑并没有让它通过,它会导致此错误:
TypeError: Cannot read property 'allowAppInstance' of null
43 | };
44 |
> 45 | export const appSetupConfig = () => setupRemote().allowAppInstance;
有什么方法可以模拟allowAppInstance以通过测试吗?我真的不知道该怎么做,我做错了什么