From 0d4149c736d5c23767ec041060ad9a0646e64a42 Mon Sep 17 00:00:00 2001 From: Jason Aden Date: Fri, 30 Nov 2018 11:35:46 -0800 Subject: [PATCH] test(router): add test verifying guards re-run when parent path segments change (#27440) Related to #26861 PR Close #27440 --- packages/router/test/integration.spec.ts | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index b030b09861..806a431e82 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -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', () => {