Testing your code is essential in todays world. You must ensure that you keep your state powerful, consistent, and understandable. Redux is framework agnostic so writing tests for it is super easy.

Actions

Actions define all the ways your state can change. Everything the user can perform an action on will be defined.

Reducers

Reducers define how actions and their payloads will be interpreted.

This reducer has four actions that be performed. It can increment or decrement a single counter, and it can remove counters from the state.

Tests

Testing is one of the most important parts of writing code. You must ensure your code is reliable.

First begin with testing the initial state of the reducer to equal an array with the first counter [0]. The next tests increments the first counter by one and after decrements the first counter. Then the final tests add and remove a counter to the array.

Conclusion

Testing Redux is fairly simple and straightforward. There are some more complex situations and asynchronous behavior that might get tricky, but in the end your app with thank you.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store