Skip to content

Commit

Permalink
test(Router): add canLoad guard rejects spec
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Oct 6, 2018
1 parent e32ecb6 commit 1919da1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions modules/router-store/spec/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>) => {
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
Expand Down

0 comments on commit 1919da1

Please sign in to comment.