I have the following method and I need to write some unit tests for it, but I cannot mock the response, I've tried using the TestScheduler but it was not successful, any help would be appreciated. I'm using jest.
protected waitForResponse(id: number, requestId: string) {
return this.service.getData(id, requestId)
.pipe(
mergeMap((resp: ResponseModel) => {
if (resp.status !== 'WAITING') {
return of(resp);
}
return throwError(resp);
}),
retryWhen(errors => errors.pipe(
concatMap((e, i) =>
iif(
() => i > 11,
// max number of 11 attempts has been reached
throwError(new HttpErrorResponse({status: HttpStatusCode.TOO_MANY_REQUESTS})),
// Otherwise try again in 5 secs
of(e).pipe(delay(5000))
)
)
)
)
);
}