1
I’m trying to test a service GET method:
get(url: string, params?: any): Observable<Response> {
let options = {};
this.securityService.setHeaders(options);
if (params)
this.setParams(options, params.params);
return this.http.get(url, options)
.pipe(
// retry(3), // retry a failed request up to 3 times
map((res: Response) => {
return res;
}),
catchError(this.handleError)
);
}
The method setHeaders
insert the request headers and the access_token, I can test it up to the part of the map
but I can’t test the return part. It would have some solution to write a test to go through the entire method?
Obs.: The method of setParams
is already being guaranteed by another test.
I tried the solution and it returned me an error, I believe it is something in Spy: Expected Spy get to have been called with [ 'fakeUrl', Object(ː }) ] but it was Never called.
– accelerate
Take a look if you are using httpClient or the older version
– Eduardo Vargas