5

I have one sagas file with 2 functions, one is the saga itself, and the other is the function that is called by my saga, which uses the eventChannel from redux-saga library.

export const hardwareBackChannel = () => eventChannel((emit): {} => {
  BackHandler.addEventListener('hardwarePress', () => {
    emit(true);
    return true; 
  });
  return (): * => {
    BackHandler.removeEventListener();
  };
});

export function* handleBackButtonEvent() {
  yield put(hardwareBackChannel());
}

I was able to test my handleBackButtonEvent successfully with:

  describe('handleBackButtonEvent', () => {
    it('should call back button pressed action', () => {
      testSaga(handleBackButtonEvent)
        .next()
        .put(
          hardwareBackChannel(),
        );
    });
  });

But I wasn't able to figure out how I can test the hardwareBackChannel itself using testSaga. Is there a way to do that? If not, how can I potentially cover this part of the code on my tests?

I've trying to search all day but I found just threads with ways to test my saga, not my hardwareBackChannel function itself.

Thanks advance

Sayuri Mizuguchi
  • 5,250
  • 3
  • 26
  • 53

0 Answers0