below are 2 methods in my service file
public getStates(countryId: number) {
let url = this.configManagerService.statesApiUrl;
const httpHeaders = this.getHeaders();
return this.httpClient.get(`${url}/${countryId}`, { headers: httpHeaders }).pipe(
catchError(this.handleError)
);
}
public handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error.message);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
console.error(`Backend returned code ${error.status}, ` + `body was: ${error.error}`);
}
// return an observable with a user-facing error message
return throwError('Value list currently not available.');
}
I am not able to write a unit test case which covers the handleError
method. Can somebody please educate me on this? Thanks.