'How to mock callback function in Jest which triggers in redux-saga using redux-toolkit

I have a dispatched action in React Component and saga listen this action and do async call

COMPONENT: dispatch(getGroups, (success) => setStatus(success))

ACTION: getGroups(state, action: { payload: (success: boolean) => void }) {},

SAGA yield takeLatest(getGroups, getGroupsList);

function* getGroupsList(action) {
  try {
    const groupsListResponse = yield call(enrollmentService.getGroupsList);
    action.payload(true);
  } catch (error: any) {
    action.payload(false);
  }
}

So, I just don't know how I could mock returned callback inside redux-saga?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source