Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test custom effect with testSaga() #362

Open
denchen opened this issue Oct 15, 2020 · 0 comments
Open

How to test custom effect with testSaga() #362

denchen opened this issue Oct 15, 2020 · 0 comments

Comments

@denchen
Copy link

denchen commented Oct 15, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant