带缓冲区的Redux-saga测试通道

时间:2017-10-12 14:35:48

标签: reactjs react-redux redux-saga

我目前正在测试redux-sagas并且在测试代码的actionChannel / buffer部分时遇到问题。这是传奇:

export function* getStatsFlow() {
  const parseChan = yield actionChannel(
    PARSE_STATS, yield 
    buffers.expanding(10)
  );

  yield fork(getAllDocumentStats);
  yield fork(getReadStats);
  yield fork(getWriteStats);

  while (true) {
    const { payload } = yield take(parseChan);
    yield call(handleParseAndPut, payload);
    yield put(finishStats());
  }
}

我目前对该传奇的测试是:

it('should begin looping', () => {
  const statsFlowSaga = getStatsFlow();
  const mockBuffer = buffers.expanding(10);
  const mockChannel = channel(mockBuffer);

  statsFlowSaga.next().value;

  expect(statsFlowSaga.next(mockBuffer).value)
    .toEqual(actionChannel(PARSE_STATS, mockBuffer));

  expect(statsFlowSaga.next().value)
    .toEqual(fork(getAllDocumentStats));

  expect(statsFlowSaga.next().value).toEqual(fork(getReadStats));

  expect(statsFlowSaga.next().value).toEqual(fork(getWriteStats));

  expect(statsFlowSaga.next(mockChannel).value)
    .toEqual(take(mockChannel));
});

最终预期现在失败,错误为"未定义patternOrChannel"。我试过传入一个mockChannel而没有传递给mockBuffer(在定义上)以及我在上面的方式。我尝试过的所有配置都产生了同样的错误。这是因为频道和缓冲区没有"链接"?我将如何解决这个问题还是有办法解决?谢谢!

0 个答案:

没有答案