From 7d2554baa161973dd3063ef07c1286d166bf327d Mon Sep 17 00:00:00 2001 From: vsavkin Date: Mon, 24 Oct 2016 14:32:11 -0700 Subject: [PATCH] tests(router): add a test showing how to handle resovle errors --- .../@angular/router/test/integration.spec.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/@angular/router/test/integration.spec.ts b/modules/@angular/router/test/integration.spec.ts index 0ee0a79cb4..302b347c51 100644 --- a/modules/@angular/router/test/integration.spec.ts +++ b/modules/@angular/router/test/integration.spec.ts @@ -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', () => {