Do you have any guidelines on testing components that use redux – more specifically connect?
Ryan Johnson

I don’t use Redux in any real production apps, so I have less exposure to it, but here’s some general guidelines:

  • Testing that connect wired your components up to the store is a concern of Redux itself, so testing connected components fails rule #2 from my post.
  • Your component tests should be around your unconnected components. If your app only cares about using your connected component, sometimes it can be useful to make a “private named export” just for using in your tests, like so:
const MyComponent = /* ... */
const MyConnectedComponent = connect(/* ... */)(MyComponent);
export default MyComponent;
export const _UnconnectedMyComponent = MyComponent;
  • You should test your mapStateToProps, mapDispatchToProps, etc functions.
  • You should use selectors throughout your store to make your state as modular as possible! This will make it easier to unit test.
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.