我正在尝试测试 rxjs 观察者的 catch 函数,但 catch 从未运行。
测试.js
it.only('On fail restore password', () => {
sandbox = sinon.stub(Observable.ajax, 'post').returns(new Error());
store.dispatch(restorePasswordVi('prueba'));
expect(store.getActions()).toInclude({ success: false, type: SET_RESTORE_PASSWORD_SUCCESS });
});
史诗请看https://redux-observable.js.org/
export function restorePasswordViEpic(action$: Observable<Action>, store: Store) {
return action$
.ofType(RESTORE_PASSWORD_VI)
.switchMap(({ user }) => {
store.dispatch(blockLoading(true));
return Observable
.ajax
.post(`${config.host}/auth/restore-password`, { user })
.map(() => setRestorePasswordSuccess(true))
.catch(() => {
return Observable.of(setMessage('Se ha producido un error por favor intente de nuevo.'));
});
});
}