Testing Redux
Because Redux reducers and action creators are just functions, and actions are simply objects, they are easy to test. Furthermore, many of those functions are pure, which means they have no side effects. Pure functions only use their arguments and constants to produce the output. This is why we only need to pass certain arguments and check the output to test the function. If there are side effects involved (which is the case for asynchronous action creators), we need to do some mocking.
Synchronous action creators
We start by writing tests for our synchronous action creators. Remember: action creators are functions which return action objects. To test them, we need to call the action creator and check if it returns the expected action object.
We are going to implement tests for the filter action creators, as they are the only synchronous ones in our application:
- Create a new directory, which will contain all action creator related tests:
__tests__/actions/
. - Create a new file:Â
__tests__...