Open ssengalanto opened 4 years ago
SagaTestError: put expectation unmet:
Expected -------- { '@@redux-saga/IO': true, combinator: false, type: 'PUT', payload: { channel: undefined, action: { type: '@@auth/AUTH_SUCCESS', payload: { user: [Object] } } } } Actual: ------ 1. { '@@redux-saga/IO': true, combinator: false, type: 'PUT', payload: { channel: undefined, action: { type: '@@auth/AUTH_SUCCESS', payload: { user: undefined } } } } 2. { '@@redux-saga/IO': true, combinator: false, type: 'PUT', payload: { channel: undefined, action: { type: '@@auth/SET_AUTH_LOADING', payload: { loading: false } } } }
Saga: export function* loginUser(action: AuthLogin) { try { yield put(setAuthLoading(true)); const { result } = yield call(authService.authenticate, action.payload.credentials); yield put(authSuccess(result)); } catch (error) { yield put(authFailed()); } finally { yield put(setAuthLoading(false)); } } function* watchAuthSaga() { yield takeLatest(AuthActionTypes.AUTH_LOGIN, loginUser); yield takeLatest(AuthActionTypes.AUTH_LOGOUT, logoutUser); } export function* authSaga() { yield all([fork(watchAuthSaga)]); } Test Case: it('should successfully login user', () => { const credentials = { username: 'username', password: 'password' }; const fakeUser = { id: 1, session_token: 'sample_token', userType: 'admin', username: 'test user', }; return expectSaga(loginUser, authLogin(credentials)) .put(setAuthLoading(true)) .provide([[matchers.call.fn(authService.authenticate), fakeUser]]) .put(authSuccess(fakeUser)) .put(setAuthLoading(false)) //.run(false) even with false param it has the same error message .run(); });
@ssengalanto Can you debug the test by console log error from the catch section?
I'm having this same issue.
did you resolve this problem? I`m having the same.
SagaTestError: put expectation unmet: