jfairbank / redux-saga-test-plan

Test Redux Saga with an easy plan.
http://redux-saga-test-plan.jeremyfairbank.com
MIT License
1.25k stars 127 forks source link

put expectation unmet (undefined) #338

Open ssengalanto opened 4 years ago

ssengalanto commented 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();
});
jp928 commented 4 years ago

@ssengalanto Can you debug the test by console log error from the catch section?

jonasarcangel commented 4 years ago

I'm having this same issue.

SiarhKul commented 3 years ago

did you resolve this problem? I`m having the same.