如何在开玩笑中测试saga yield观察者并行调用

时间:2017-08-23 04:39:15

标签: jestjs redux-saga saga redux-saga-test-plan

我想测试我的传奇我能够测试单个传奇电话,但我如何使用jest测试我的观察者传奇

export default function* saga() {
  yield [
    takeLatest(dataTypeActions.ACTION1, fetchDataType),
    takeLatest(sourceActions.ACTION2, fetchFromSource),
    takeLatest(targetActions.ACTION3, fetchFromTarget),
  ];
}

某些正文将帮助我如何使用jest(uisng生成器函数)测试并行调用

1 个答案:

答案 0 :(得分:1)

你可以这样测试:

it('watches several actions...', () => {
  const generator = yourSaga();
  expect(generator.next().value).toEqual([
    takeLatest(dataTypeActions.ACTION1, fetchDataType),
    takeLatest(sourceActions.ACTION2, fetchFromSource),
    takeLatest(targetActions.ACTION3, fetchFromTarget),
  ]);
});