I want to unit test the following guard
resolve(): Observable < Game > {
return this.gameRoom$.pipe(
tap(data => {
this.gameService.updateGame(data);
}));
}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): boolean {
this.gameRoom$ = this.gameService.fetchGame(next.paramMap.get("gameId")).pipe(shareReplay());
return this.gameService.isRouteCorrectlyConfigured(state.url);
}
I have setup the following unit tests for CanActivate
it("it should not activate route", () => {
const MockSnapshot = {
url: ""
} as RouterStateSnapshot;
expect(guard.canActivate(route.snapshot, MockRouterStateSnapshot)).toBeFalsy();
});
it("it should activate route", () => {
const MockRouterStateSnapshot = {
url: "/game/someid/some-place"
} as RouterStateSnapshot;
expect(guard.canActivate(route.snapshot, MockRouterStateSnapshot)).toBeTruthy();
});
But how can I unit test the resolve method? I tried it like this, but the observable does not exist since the gameService is not fetching anything. Does it even make sense to test the resolve method? How can I test it?
it("should resolve", () => {
guard.resolve().subscribe(data => expect(data).toBeTruthy());
});