0

I have the following in an Epic:

mergeMap(result => concat(
  of(fetchDone(result)),
  of(dispatchActions(payload))
))

And actions:

const fetchDone = result => ({ type: "FETCH_DONE", payload: result });

function dispatchActions(payload) {
  return dispatch => {
     dispatch(doStuff(payload));
     ...
  };
}

The issue is in my test using marbles, I need to be able to check for the anonymous function because dispatchActions is seen as anonymous. How do I do that?

const values = {
  ...
  b: { type: "FETCH_DONE", payload: expected },
  c: NEEDS TO BE ANONYMOUS
};

...
const output$ = fetchApi(action$, state$);

// This fails due to the anonymous function
expectObservable(output$).toBe('---(bc)--', values);
NJB
  • 51
  • 4

1 Answers1

0

As a workaround, I'm doing:

function dispatchActions(payload) {
  if (payload.callDispatches) {
    return dispatch => {
      dispatch(doStuff(payload));
      ...
    };
  }
  return { type: "SOME_TYPE" };
}

Then in the unit test, I just check against the 2nd return. And the if-condition test can just be handled in a separate test outside of marbles.

This isn't ideal, but solves the issue for now. There should be some way to test redux-thunks using marbles though.

NJB
  • 51
  • 4