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

take assertion with redux-saga-test-plan that takes a function as pattern gives 'take effects do not match' error #355

Open lolero opened 4 years ago

lolero commented 4 years ago

I want to test a saga that yields a take effect which takes a function as pattern, e.g.

export function* mySaga(myAction: {
  type: string;
}): Generator<TakeEffect, boolean, { type: string }> {
  const { type: actionType } = (yield take(
    (action: any) => action.type === myAction.type,
  )) as { type: string };
  return actionType === myAction.type;
}

with a test that looks like:

it('Should test mySaga', () => {
  testSaga(mySaga, { type: 'myActionType' }).next().take().next().finish();
});

but I get the following error:

SagaTestError: 
Assertion 1 failed: take effects do not match

Expected
--------
{ '@@redux-saga/IO': true,
  combinator: false,
  type: 'TAKE',
  payload: { pattern: '*' } }

Actual
------
{ '@@redux-saga/IO': true,
  combinator: false,
  type: 'TAKE',
  payload: { pattern: [Function] } }

I have not been able to find how to assert the a take effect that takes a function pattern instead of a string. Can someone please help me?