Skip to content

Commit

Permalink
fix(router): add a test to make sure canDeactivate guards are called …
Browse files Browse the repository at this point in the history
…for aux routes

Closes angular#11345
  • Loading branch information
vsavkin committed Oct 20, 2016
1 parent f53d1c7 commit b86e34c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions modules/@angular/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,34 @@ describe('Integration', () => {
]);
})));

it('works with aux routes',
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const fixture = createRoot(router, RootCmp);

router.resetConfig([{
path: 'two-outlets',
component: TwoOutletsCmp,
children: [
{path: 'a', component: BlankCmp}, {
path: 'b',
canDeactivate: ['RecordingDeactivate'],
component: SimpleCmp,
outlet: 'aux'
}
]
}]);

router.navigateByUrl('/two-outlets/(a//aux:b)');
advance(fixture);
expect(location.path()).toEqual('/two-outlets/(a//aux:b)');

router.navigate(['two-outlets', {outlets: {aux: null}}]);
advance(fixture);

expect(log).toEqual([['Deactivate', 'b']]);
expect(location.path()).toEqual('/two-outlets/(a)');
})));

it('works with a nested route',
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const fixture = createRoot(router, RootCmp);
Expand Down Expand Up @@ -1868,6 +1896,14 @@ class TeamCmp {
}
}

@Component({
selector: 'two-outlets-cmp',
template: `[ <router-outlet></router-outlet>, aux: <router-outlet name="aux"></router-outlet> ]`
})
class TwoOutletsCmp {
}


@Component({selector: 'user-cmp', template: `user {{name | async}}`})
class UserCmp {
name: Observable<string>;
Expand Down Expand Up @@ -1970,6 +2006,7 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
entryComponents: [
BlankCmp,
SimpleCmp,
TwoOutletsCmp,
TeamCmp,
UserCmp,
StringLinkCmp,
Expand All @@ -1994,6 +2031,7 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
exports: [
BlankCmp,
SimpleCmp,
TwoOutletsCmp,
TeamCmp,
UserCmp,
StringLinkCmp,
Expand All @@ -2020,6 +2058,7 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
BlankCmp,
SimpleCmp,
TeamCmp,
TwoOutletsCmp,
UserCmp,
StringLinkCmp,
DummyLinkCmp,
Expand Down

0 comments on commit b86e34c

Please sign in to comment.