Here I'm using redux-observable
and having some issues testing the error handling.
See the following logout user epic:
const logoutUserEpic = (action$) => action$
.ofType(LOGOUT_USER)
.mergeMap(() =>
Observable.from(
graphQl(AuthLogout)
.catch((error) => failure(error))
)
.mergeMap(() => Observable.of(
receive(),
push('/login')
)
)
)
Here's a test that mocks out the graphQl
service to make sure that it fires the failure action when the promise rejects:
it('should return the error action', () => {
const error = Error('fail')
request.graphQl = () => Promise.reject(error)
const action$ = ActionsObservable.of((logoutUser()))
return logoutUserEpic(action$)
.toArray()
.forEach((actions) => {
expect(actions).toEqual([{
meta: { isFetching: false },
payload: error,
type: FAILURE
}])
})
})
In the test it dispatches the actions that are flattened in mergeMap rather than the expected failure action in the catch.
Is it valid to have the error handling set up like this or am I showing my noobishness with RxJs?