test(router): add test verifying guards re-run when parent path segments change (#27440)

Related to #26861

PR Close #27440
This commit is contained in:
Jason Aden 2018-11-30 11:35:46 -08:00 committed by Igor Minar
parent 862697d4bd
commit 0d4149c736
1 changed files with 37 additions and 0 deletions

View File

@ -2263,6 +2263,18 @@ describe('Integration', () => {
component: RouteCmp,
canActivate: ['guard'],
resolve: {data: 'resolver'}
},
{
path: 'd/:param',
component: WrapperCmp, runGuardsAndResolvers,
children: [
{
path: 'e/:param',
component: SimpleCmp,
canActivate: ['guard'],
resolve: {data: 'resolver'},
},
]
}
]);
@ -2411,6 +2423,31 @@ describe('Integration', () => {
advance(fixture);
expect(guardRunCount).toEqual(3);
})));
it('should rerun when a parent segment changes',
fakeAsync(inject([Router], (router: Router) => {
const fixture = configureRouter(router, 'pathParamsChange');
const cmp: RouteCmp = fixture.debugElement.children[1].componentInstance;
// Land on an inital page
router.navigateByUrl('/d/1;dd=11/e/2;dd=22');
advance(fixture);
expect(guardRunCount).toEqual(2);
// Changes cause re-run on the config with the guard
router.navigateByUrl('/d/1;dd=11/e/3;ee=22');
advance(fixture);
expect(guardRunCount).toEqual(3);
// Changes to the parent also cause re-run
router.navigateByUrl('/d/2;dd=11/e/3;ee=22');
advance(fixture);
expect(guardRunCount).toEqual(4);
})));
});
describe('should wait for parent to complete', () => {