What Is The Purpose Of Redux Async Action Testing?

- 1 answer

Could someone explain why we test asynchronous actions? What are we hoping to ensure works?

So in the docs,, we mock the server request.

  .reply(200, { todos: ['do something'] })

const expectedActions = [
  { type: types.FETCH_TODOS_REQUEST },
  { type: types.FETCH_TODOS_SUCCESS, body: { todos: ['do something']  } }
const store = mockStore({ todos: [] }, expectedActions, done)

So we aren't testing to see if we contact the server. We are testing to see if the correct sequence of actions takes place, given a response of 200 correct?



Yes, the point of this type of test isn't to see if your network requests are working correctly but to ensure that the sequence of actions that you expect to fire is actually firing. It can also be used to make sure that the data you get back from the server is the correct format your front end expects.

This may seem trivial if you write the tests after you've implemented the code, but say that down the road, you or another developer decides to make some slight tweaks to those actions or remove one entirely. Worst case scenario, your code fails silently, leaving you to wonder what went wrong. These types of tests help you avoid that kind of problem.