0

I'm using redux-saga-test-plan to test my sagas for redux-saga. While debugging my tests I've noticed that my reducer receives one unexpected action, with type === "@@redux-saga-test-plan/INIT".

I do not see any mention of this @@redux-saga-test-plan/INIT action type in redux-saga-test-plan documentation. What is the purpose of this action? Should I handle it in some special way?

TMG
  • 2,620
  • 1
  • 17
  • 40

1 Answers1

0

A reducer is a function that, when bound to the store, will be called regardless of what action has been dispatched, so it always has to accommodate for unexpected action types. By far the most common way to do this is to do nothing, which in (state, action) -> state kind of function signature means just returning the state itself without any changes:

switch (action.type) {
  case ABC: do something; break;
  case XYZ: do something; break;
  default: return state; // <- default "response" to actions that aren't handled by code above: stay chill, do nothing, return the state as is
}

The action @@redux-saga-test-plan/INIT is internal for the redux-saga-test-plan lib. Because there is no way an action, once dispatched, can be skipped or hidden from the workflow (or developer tools), you might have seen many actions of types that look similar to that one. Don't worry, those are most likely used by libs themselves and don't require any specific handling from your side.

rishat
  • 8,206
  • 4
  • 44
  • 69
  • That's what I expected too, and just returning the state as default action is exactly what I do. However I've noticed that my saga is working differently in tests and production code - in particular the state in tests gets corrupted right after getting this `@@redux-saga-test-plan/INIT` action. This is the last action for which reducer gets state in expected format. That's why I started to wonder what is this, what it means and if it requires some special handling. – TMG Jan 31 '19 at 15:19