I have to write Unit Test for this effect that is calling the service every 1 sec when it went in error. I need to test for example that after 3 times of calling a service, I'll receive a good response.
I tried some way to test but without any result.
This is the effect that I have to test:
@Effect()
updateEffect$ = this.actions$.pipe(
ofType(featureActions.ActionTypes.UPDATE_PRODUCT),
switchMap((action: UpdateProduct) =>
this.productService.getProducts().pipe(
retryWhen((attempts) => attempts.pipe(delay(1000))),
map((productsResponse: Products) =>
productsResponse
? new featureActions.LoadProductSuccess(productsResponse)
: new featureActions.LoadProductError(productsResponse)
)
)
)
);
This is the unit test that I did just to see the success scenario. What I want to test is the reload logic
it('should return UpdateProduct if service response success ', () => {
const action = new UpdateProduct('123456');
const completion = new LoadProductSuccess(productsResponseMock);
actions$ = hot('-a-', { a: action });
const response = cold('-b', { b: productsResponseMock });
const expected = cold('--c', { c: completion });
productService.getProducts.and.returnValue(response);
expect(effects.updateEffect$).toBeObservable(expected);
});