tests(router): add a test showing how to handle resovle errors

This commit is contained in:
vsavkin 2016-10-24 14:32:11 -07:00
parent 52a853e257
commit 7d2554baa1
1 changed files with 24 additions and 1 deletions

View File

@ -623,7 +623,8 @@ describe('Integration', () => {
providers: [
{provide: 'resolveTwo', useValue: (a: any, b: any) => 2},
{provide: 'resolveFour', useValue: (a: any, b: any) => 4},
{provide: 'resolveSix', useClass: ResolveSix}
{provide: 'resolveSix', useClass: ResolveSix},
{provide: 'resolveError', useValue: (a: any, b: any) => Promise.reject('error')},
]
});
});
@ -672,6 +673,28 @@ describe('Integration', () => {
{one: 1, five: 5, two: 2, six: 6}, {one: 1, five: 5, two: 2, six: 6}
]);
})));
it('should handle errors',
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
const fixture = createRoot(router, RootCmp);
router.resetConfig(
[{path: 'simple', component: SimpleCmp, resolve: {error: 'resolveError'}}]);
let recordedEvents: any[] = [];
router.events.subscribe(e => recordedEvents.push(e));
let e: any = null;
router.navigateByUrl('/simple').catch(error => e = error);
advance(fixture);
expectEvents(recordedEvents, [
[NavigationStart, '/simple'], [RoutesRecognized, '/simple'],
[NavigationError, '/simple']
]);
expect(e).toEqual('error');
})));
});
describe('router links', () => {