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 call a call back function in action's payload #372

Open vandiepbui opened 3 years ago

vandiepbui commented 3 years ago

Hi,

I have a callback function in payload. Please tell me how to call that callback function when testSaga.

My saga.js export const sumTwoNumbers = function* ({ payload: { a, b, onSuccess } }) { try { let sum = a + b; yield put(sumTwoNumbersSuccess()); yield call(onSuccess(sum)); } catch(e) { console.log(e) } };

My saga.test.js

describe('sum two numbers', () => { const actionPayload = { type: 'SUM_TWO_NUMBER', payload: { a: 5, b: 6, onSuccess: () => 11, }, };

it('should sum two numbers success', () => { testSaga(sumTwoNumbers, actionPayload) .next() .put(sumTwoNumbersSuccess()) .next() .isDone(); }); });

I want to call onSuccess function in unit test. Please help me! Thanks so much!