我有以下代码来异步加载依赖项:
declare global {
interface Window {
System: System.Module
}
}
const fooService = window.System.import('@internal/foo-service').then(module => module.FooService)
// ^ Jest trips up here
async function func1() {
(await fooService).doBar()
…
}
async function func2() {
(await fooService).doBar2()
…
}
感谢Bergi ,这很好用,但 Jest 绊倒了window.System.import
,给了我错误Cannot read property 'import' of undefined
。我怎样才能正确地模拟这个?