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

Open
vandiepbui opened this issue Aug 27, 2021 · 0 comments
Open

How to call a call back function in action's payload #372

vandiepbui opened this issue Aug 27, 2021 · 0 comments

Comments

@vandiepbui
Copy link

vandiepbui commented Aug 27, 2021

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!

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