1

So I have a saga which shows fetches some data to show in a table.

Action Creators are as follows

export const fetchInstanceDataSetAssocSuccess = (records) => {
  return {
    type: actionTypes.FETCH_INSTANCE_DATASETS_ASSOC_SUCCESS,
    records: records
  }
 }

export const fetchInstanceDataSetAssocFailed = (error) => {
  return {
    type: actionTypes.FETCH_INSTANCE_DATASETS_ASSOC_FAILED,
    error: error
  }
}

export const fetchInstanceDataSetAssocStart = () => {
  return {
   type: actionTypes.FETCH_INSTANCE_DATASETS_ASSOC_START
  }
}

export const fetchInstanceDataSetAssoc = () => {
   return {
     type: actionTypes.FETCH_INSTANCE_DATASETS_ASSOC_INITIATE
   }
}

My saga is as follows

    function * fetchInstanceDataSetAssocSaga (action) {
      yield put(instanceDataSetAssocActions.fetchInstanceDataSetAssocStart())
      const useMockData = yield constants.USE_MOCK_DATA
      if (useMockData) {
        yield delay(constants.MOCK_DELAY_SECONDS * 1000)
      }
      try {
        const res = (useMockData)
         ? (yield constants.INSTANCE_DATASET_ASSOC)
         : (yield call(request, {url: 
         API_URLS.INSTANCE_DATASET_ASSOC_API_ENDPOINT, method: 'GET'}))

    yield put(instanceDataSetAssocActions.fetchInstanceDataSetAssocSuccess(res.data))
    } catch (error) {
       yield 
put(instanceDataSetAssocActions.fetchInstanceDataSetAssocFailed(error))
  }
}

Action to watch over the Saga is as follows

export function * watchInstanceDataSetAssocSaga () {
  yield takeEvery(actionTypes.FETCH_INSTANCE_DATASETS_ASSOC_INITIATE, 
  fetchInstanceDataSetAssocSaga)
}

Test Cases are as follows

  describe('load instance dataset assoc table', () => {
  test('update state with  instance-dataset records for landing page',() => {
    const finalState = {
      records: constants.INSTANCE_DATASET_ASSOC.data,
      loading: false,
      error: false
    }
    const requestParam = {url: API_URLS.INSTANCE_DATASET_ASSOC_API_ENDPOINT, method: 'GET'}
    return expectSaga(watchInstanceDataSetAssocSaga)
      .provide([[call(request,requestParam),constants.INSTANCE_DATASET_ASSOC]])
      .withReducer(instanceDataSetAssoc)
      .put(instanceDataSetAssocActions.fetchInstanceDataSetAssocStart())
      .put(instanceDataSetAssocActions.fetchInstanceDataSetAssocSuccess(constants.INSTANCE_DATASET_ASSOC.data))
      .dispatch(instanceDataSetAssocActions.fetchInstanceDataSetAssoc())
      .hasFinalState(finalState)
      .silentRun()
  })
})

I get the following error for this.

 SagaTestError:
put expectation unmet:
at new SagaTestError (node_modules/redux-saga-test-plan/lib/shared/SagaTestError.js:17:57)
  at node_modules/redux-saga-test-plan/lib/expectSaga/expectations.js:63:13
  at node_modules/redux-saga-test-plan/lib/expectSaga/index.js:572:7
      at Array.forEach (<anonymous>)
  at checkExpectations (node_modules/redux-saga-test-plan/lib/expectSaga/index.js:571:18)

I am following the docs correctly but still getting the above error.

anuragb26
  • 1,467
  • 11
  • 14

1 Answers1

1

Maybe its late, but i found an answer, maybe it will help you This mistake may occure because of library timeout try to turn off the timeout with .run(false) original link https://github.com/jfairbank/redux-saga-test-plan/issues/54