最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

redux - Why does expectSaga(watchLayoutFlow).take(OPEN_MAP).run(); throw "saga argument must be a Generator function!&a

programmeradmin3浏览0评论

I am trying to test a Redux-Saga using redux-saga-test-plan, but I keep getting the error:

runSaga(options, saga, ...args): saga argument must be a Generator function!

Here is my saga:

export function* watchLayoutFlow(): SagaIterator {
  yield takeEvery(actionTypes.CHANGE_INTERFACE_SETTINGS, changeInterfaceSettings);
  yield takeEvery(actionTypes.OPEN_MAP, openMap);
  yield takeEvery(actionTypes.OPEN_WORK_AREA, openWorkArea);
}

export function* rootSaga(): SagaIterator {
  yield fork(watchLayoutFlow);
}

And my test:

import { expectSaga } from 'redux-saga-test-plan';
import { OPEN_MAP } from '../../../actions/ActionTypes';
import { watchLayoutFlow } from '../../../sagas/Sagas';

describe('Call flow tests', () => {
  it('Should execute takeEvery for OPEN_GMAP', () => {
    return expectSaga(watchLayoutFlow).take(OPEN_MAP).run();
  });
});

What I have tried

  • The application runs fine, but the test fails with the above error.

  • I checked that watchLayoutFlow is correctly exported as a generator function.

  • I confirmed that redux-saga-test-plan is correctly installed.

Dependencies

  • "react": "^18.2.0"

  • "react-redux": "^9.2.0"

  • "redux": "^5.0.1"

  • "redux-saga": "1.3.0"

  • "redux-saga-test-plan": "4.0.6"

  • "jest": "26.6.3"

What could be causing this error?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论