我正在使用RouterTestingModule,我的测试是
it('should navigate to foo child path', fakeAsync(() => {
let router = TestBed.get(Router);
let location = TestBed.get(Location);
let fixture = TestBed.createComponent(AppComponent);
router.initialNavigation();
router.navigateByUrl('/foo/child');
tick();
fixture.detectChanges();
expect(location.path()).toBe('/foo/child');
}));
Run Code Online (Sandbox Code Playgroud)
当尝试测试具有延迟加载的孩子的路线时,例如
{ path: 'foo', loadChildren: 'app/foo/foo.module#FooModule'}
Run Code Online (Sandbox Code Playgroud)
抛出错误"无法找到模块...".
Error: Uncaught (in promise): Error: Cannot find module app/foo/foo.module#FooModule
Error: Cannot find module app/foo/foo.module#FooModule
at SpyNgModuleFactoryLoader.Array.concat.SpyNgModuleFactoryLoader.load (webpack:///~/@angular/router/@angular/router/testing.es5.js:78:0 <- src/test.ts:92347:35) [ProxyZone]
at RouterConfigLoader.Array.concat.RouterConfigLoader.loadModuleFactory (webpack:///~/@angular/router/@angular/router.es5.js:3417:0 <- src/test.ts:24005:129) [ProxyZone]
at RouterConfigLoader.Array.concat.RouterConfigLoader.load (webpack:///~/@angular/router/@angular/router.es5.js:3401:25 <- src/test.ts:23989:52) [ProxyZone]
at MergeMapSubscriber.project (webpack:///~/@angular/router/@angular/router.es5.js:1569:0 <- src/test.ts:22157:108) [ProxyZone]
at MergeMapSubscriber.Array.concat.MergeMapSubscriber._tryNext (webpack:///~/rxjs/operator/mergeMap.js:120:0 <- src/test.ts:57460:27) …Run Code Online (Sandbox Code Playgroud) angular ×1