From 1919da1c327aabb11a9f5a4d3cd4618c1a020e58 Mon Sep 17 00:00:00 2001 From: timdeschryver Date: Sat, 6 Oct 2018 20:16:25 +0200 Subject: [PATCH] test(Router): add canLoad guard rejects spec --- modules/router-store/spec/integration.spec.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/modules/router-store/spec/integration.spec.ts b/modules/router-store/spec/integration.spec.ts index f1b11d7b87..2c6710250f 100644 --- a/modules/router-store/spec/integration.spec.ts +++ b/modules/router-store/spec/integration.spec.ts @@ -526,6 +526,44 @@ describe('integration spec', () => { }); }); + it('should support cancellation of initial navigation when canLoad guard rejects', (done: any) => { + const reducer = (state: any, action: RouterAction) => { + const r = routerReducer(state, action); + return r && r.state + ? { url: r.state.url, navigationId: r.navigationId } + : null; + }; + + createTestModule({ + reducers: { routerReducer, reducer }, + canLoad: () => Promise.reject('boom'), + }); + + const router: Router = TestBed.get(Router); + const log = logOfRouterAndActionsAndStore(); + + router + .navigateByUrl('/load') + .then(() => { + fail(`Shouldn't be called`); + }) + .catch(r => { + expect(r).toBe('boom'); + + expect(log).toEqual([ + { type: 'store', state: null }, // initial state + { type: 'store', state: null }, // ROUTER_REQEST event in the store + { type: 'action', action: ROUTER_REQUEST }, + { type: 'router', event: 'NavigationStart', url: '/load' }, + { type: 'store', state: { url: '', navigationId: 1 } }, + { type: 'action', action: ROUTER_ERROR }, + { type: 'router', event: 'NavigationError', url: '/load' }, + ]); + + done(); + }); + }); + function shouldSupportCustomSerializer( serializerThroughConfig: boolean, done: Function