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

How to test custom effect with testSaga() #362

Open denchen opened 3 years ago

denchen commented 3 years ago

I have a custom effect called takeLeadingPerKey() which is based off of takeLeading() but allows multiple sagas to run as long as they have a unique key.

I'm not sure how to use it with testSaga()

Example code:

/**
 * takeLeadingPerKey() signature:
 *   function takeLeadingPerKey(patternOrChannel, worker, keySelector, ...args)
 */

function* doSomething(action) {
  // Do something
}

function selectKey(action) {
  return action.meta.key;
}

export function* mySaga() {
  yield takeLeadingPerKey(
    'MY_TYPE',
    doSomething,
    selectKey
  );
}

Example test:

testSaga(mySaga)
  .next()
  .takeLeadingPerKey('MY_TYPE', doSomething, selectKey)
  .next()
  .isDone();

With the above, I get:

TypeError: (0 , _reduxSagaTestPlan.testSaga)(...).next(...).takeLeadingPerKey is not a function

Obviously it's complaining that takeLeadingPerKey() doesn't exist with testSaga(), so is there another way to test this?