填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

SpyNgModuleFactoryLoader

允许模拟测试中 ng 模块的加载。

Allows to simulate the loading of ng modules in tests.

查看"说明"...

      
      class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader {
  stubbedModules: {...}
  load(path: string): Promise<NgModuleFactory<any>>
}
    

说明

      
      const loader = TestBed.inject(NgModuleFactoryLoader);

@Component({template: 'lazy-loaded'})
class LazyLoadedComponent {}
@NgModule({
  declarations: [LazyLoadedComponent],
  imports: [RouterModule.forChild([{path: 'loaded', component: LazyLoadedComponent}])]
})

class LoadedModule {}

// sets up stubbedModules
loader.stubbedModules = {lazyModule: LoadedModule};

router.resetConfig([
  {path: 'lazy', loadChildren: 'lazyModule'},
]);

router.navigateByUrl('/lazy/loaded');
    

属性

属性说明
stubbedModules: { [path: string]: any; }

方法

      
      load(path: string): Promise<NgModuleFactory<any>>
    
参数
path string
返回值

Promise<NgModuleFactory<any>>