2
votes

I've been trying to test a react+redux application and came across a problem. My reducer expects action of type "FOO" to bo a nested Javascript object, like here:

{
  type: "FOO"
  data: {
    bar: "foo"
  }
}

When I passed an object without data field to the reducer in my test, the reducer obviously crashed.

My question is: While implementing/testing reducers can I assume, that action creators have already handled errors and actions of given types are always properly structured, or should handle errors in reducers as well (which might cause a risk of faulty state passed to components and selectors and makes error handling a nightmare)? Or do I miss something?

1

1 Answers

3
votes

A dispatcher checks the action for the type attribute only.

Reducer does not check the action for any attribute at all. All the action objects need to be checked and handled for errors accordingly.

Another way to check for errors can be using a middleware if you want to avoid checking inside a reducer.