linkSpyNgModuleFactoryLoader
npm Package | @angular/router |
---|---|
Module | import { SpyNgModuleFactoryLoader } from '@angular/router/testing'; |
Source | router/testing/src/router_testing_module.ts |
Allows to simulate the loading of ng modules in tests.
linkOverview
class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader {
constructor(compiler: Compiler)
stubbedModules: {...}
load(path: string): Promise<NgModuleFactory<any>>
}
linkHow To Use
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');
linkConstructor
constructor(compiler: Compiler)
linkMembers
load(path: string): Promise<NgModuleFactory<any>>
linkAnnotations
@Injectable()