I have the following method
getWsById(idWs: number, isCache: boolean = true): Observable<WSModel> {
try {
if (isCache) {
const answer: WSModel = this.fullWSModelCache$
.getValue()
.filter((fullWS) => fullWS.workspace.workspaceId === idWs)
.map((fullWS) => fullWS.workspace)[0];
return of(answer);
}
const params = new HttpParams().set('idWs', idWs.toString());
const wsResponse = this.http.get<WSModel>('rest/ws/ws-by-id', {
params
});
return wsResponse;
} catch (error) {
this.updateHasError(true);
console.error(`Error occurred: ${error}`);
}
}
I want to write a unit test that check the cache mode and verify that there was no Rest call. How to achieve this ? I dont have the slightest idea!!!
My current test is like below
it("should test getWsById cache mode", () => {
wsService.updateFullWsModelCache(currentFullWSModelCache);
wsService.getWsById(testingWsModel.workspaceId).subscribe( res => expect(res).toEqual(testingWsModel));
const req = httpTestingController.expectOne({
method: 'GET'
});
//expect(req.countOfCalls).toEqual(0); how to achieve this
});