From ceb61d10c186b941c6a2b0fb1ad11ff4c49d2161 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Fri, 17 Apr 2020 16:12:24 -0700 Subject: [PATCH] test(router): add canDeactivate test for forChild route (#36699) This PR adds test case to cover a failure that was detected after merging #36302. That commit will be reverted and will need a new PR that does not cause this test to fail. PR Close #36699 --- packages/router/test/integration.spec.ts | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 358f4ccc46..b6882f5c6d 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -3077,6 +3077,47 @@ describe('Integration', () => { }))); }); + it('should use correct component to deactivate forChild route', + fakeAsync(inject( + [Router, Location, NgModuleFactoryLoader], + (router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => { + @Component({selector: 'admin', template: ''}) + class AdminComponent { + } + + @NgModule({ + declarations: [AdminComponent], + imports: [RouterModule.forChild([{ + path: '', + component: AdminComponent, + canDeactivate: ['RecordingDeactivate'], + }])], + }) + class LazyLoadedModule { + } + + loader.stubbedModules = {lazy: LazyLoadedModule}; + const fixture = createRoot(router, RootCmp); + + router.resetConfig([ + { + path: 'a', + component: WrapperCmp, + children: [ + {path: '', pathMatch: 'full', loadChildren: 'lazy'}, + ] + }, + {path: 'b', component: SimpleCmp}, + ]); + + router.navigateByUrl('/a'); + advance(fixture); + router.navigateByUrl('/b'); + advance(fixture); + + expect(log[0].component).toBeAnInstanceOf(AdminComponent); + }))); + it('should not create a route state if navigation is canceled', fakeAsync(inject([Router, Location], (router: Router, location: Location) => { const fixture = createRoot(router, RootCmp);