Help Angular by taking a 1 minute survey!Go to surveyHome

SpyNgModuleFactoryLoader

Allows to simulate the loading of ng modules in tests.

See more...

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

Description

const loader = TestBed.get(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');
      
      
  1. const loader = TestBed.get(NgModuleFactoryLoader);
  2.  
  3. @Component({template: 'lazy-loaded'})
  4. class LazyLoadedComponent {}
  5. @NgModule({
  6. declarations: [LazyLoadedComponent],
  7. imports: [RouterModule.forChild([{path: 'loaded', component: LazyLoadedComponent}])]
  8. })
  9.  
  10. class LoadedModule {}
  11.  
  12. // sets up stubbedModules
  13. loader.stubbedModules = {lazyModule: LoadedModule};
  14.  
  15. router.resetConfig([
  16. {path: 'lazy', loadChildren: 'lazyModule'},
  17. ]);
  18.  
  19. router.navigateByUrl('/lazy/loaded');

Properties

Property Description
stubbedModules: { [path: string]: any; }

Methods

load(path: string): Promise<NgModuleFactory<any>>
      
      load(path: string): Promise<NgModuleFactory<any>>
    
Parameters
path string
Returns

Promise<NgModuleFactory<any>>