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
This commit is contained in:
Andrew Scott 2020-04-17 16:12:24 -07:00 committed by Matias Niemelä
parent dd806b0d99
commit ceb61d10c1
1 changed files with 41 additions and 0 deletions

View File

@ -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);