fix(router): add a test to make sure canDeactivate guards are called for aux routes

Closes #11345
This commit is contained in:
vsavkin 2016-10-20 14:00:02 -07:00
parent b74185369f
commit fc60fa790c
1 changed files with 39 additions and 0 deletions

View File

@ -1147,6 +1147,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);
@ -2057,6 +2085,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>;
@ -2159,6 +2195,7 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
entryComponents: [
BlankCmp,
SimpleCmp,
TwoOutletsCmp,
TeamCmp,
UserCmp,
StringLinkCmp,
@ -2183,6 +2220,7 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
exports: [
BlankCmp,
SimpleCmp,
TwoOutletsCmp,
TeamCmp,
UserCmp,
StringLinkCmp,
@ -2209,6 +2247,7 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
BlankCmp,
SimpleCmp,
TeamCmp,
TwoOutletsCmp,
UserCmp,
StringLinkCmp,
DummyLinkCmp,