Testing a Modern Redux Application

Learn how to test a modern Redux application.

We'll cover the following

Automated Testing

In the past, testing a Redux application may have seemed like it required advanced testing knowledge that differs from those for testing a regular React application. Well, that’s no longer the case.

First, let’s consider unit testing.

Before the Redux toolkit, you may have had to write unit tests for all your action creators and reducers. But do you have to do so now?

Well, it depends.

If you write these, you aren’t testing whether createAction, createReducer, or createSlice from RTK works properly. These are already well tested in the RTK library. Your tests really just check that you’re using these methods correctly.

If the project is built using Typescript, then you could get away with not writing these unit tests. The Typescript compiler will check your syntax anyway, e.g., making sure the RTK methods are invoked with the right arguments.

These unit tests may offer some confidence for refactoring, but rightly judge whether you need to do this or not. You may be better off spending time writing better integration or functional tests, which is where things get interesting.

With these functional or integration tests, nothing particularly “Redux-specific" jumps out at you. Just write these tests like you would a React application.

The library of choice for many standard frontend projects is react-testing-library. If you’re already familiar with testing react applications, you’ll do just fine with your Redux apps!

Usage with Typescript

Typescript is the Javascript superset language that you’ve probably heard before.

This isn’t a Typescript course, but there are excellent reasons to use Typescript in your frontend project.

If you choose to write Typescript with Redux toolkit, it has excellent support for Typescript, so you’d be in good hands! I recommend taking a look at the official “Usage With Typescript” guide.

Get hands-on with 1200+ tech skills courses.