From the course: Building Modern Projects with React

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Testing reducers

Testing reducers

From the course: Building Modern Projects with React

Start my 1-month free trial

Testing reducers

- The first Ecosystem tool we're going to look at testing is Redux. Testing reducers is very important in a React Redux application. They control the central state of our app, so it's pretty vital for them to work correctly under all normal circumstances. The good news is that testing reducers is actually quite easy. Reducers are pure functions, which means that they have no internal state for us to set up. We simply have to define a current state and an action, and pass those two arguments to our reducer to see if it returns what we expected it to. So let's walk through an example to show you exactly what I'm talking about here. We're going to write a test for our todos reducer. The first thing we're going to do is inside this tests folder, let's make a new file called reducers.test.js, and we need to name it .test.js so that Mocha will find it with the command we're running. And then inside this file, we're going to…

Contents