Simplifying Basic Reducer Test
Understand how to simplify testing Redux reducers by using the reducer itself to generate initial state. Learn techniques to write maintainable tests that adapt to changes in state structure, ensuring your Redux state management remains reliable and consistent.
We'll cover the following...
Using the method of writing tests described in the previous lesson, we will need to find each test definition’s initial state and add more properties. This complicates the test writer’s job without providing any benefits. Luckily, the reducer already creates non-empty states. Since we already tested adding to an empty list in the first test, we can rely on our reducer to create a non-empty list with all the required recipe information. You pass an empty array into the reducer and it fills it with the relevant state:
// Building initial state ...