1. 5
    Adding Tests for a Redux Reducer
    4m 5s

Adding Tests for a Redux Reducer

InstructorJamund Ferguson

Share this video with your friends

Send Tweet

This test starts us off with testing a reducer and we do that by import both the reducer and an associated action creator, which we can use to generate an actions to pass back into that reducer.

For all of our unit tests here we use describe blocks to group them even though they're not strictly required. When using this approach a good way to think about naming your tests is if you construct a sentence starting from the describe block text and then concluding with the test name passed into it. For example you can read one of these tests as "products reducer should convert the products received to an object".

One thing we use extensively in our tests is the products json file that we share with our app. In practice, your app likely won't have a products.json file. That data likely will come from something a bit more dynamic like an API and so you might need to create a file like this just for your tests.

If you're just getting started with jest you can checking out their getting started guide or choose from whole slew of jest lessons here on egghead. Another fantastic resource is Kent C. Dodd's https://testingjavascript.com/ which is a paid course.