title: Error: Action may not be undefined in async action testing in Redux app with nock and mock-store
body: <p>bit stumped with this one. Following the Redux docs to setup tests for my async actions (<a href="http://redux.js.org/docs/recipes/WritingTests.html" rel="nofollow noreferrer">docs here</a>), I am getting the error:</p>
  
  <blockquote>
    <p>Actions may not be an undefined. (at dispatch (node_modules/redux-mock-store/lib/index.js:35:19))</p>
  </blockquote>
  
  <p>Testing this action:</p>
  
  <pre><code>export const FETCH_TRANSACTIONS = 'FETCH_TRANSACTIONS'
  
  function fetchTransactionsSuccess (transactions) {
    return {
      type: FETCH_TRANSACTIONS,
      payload: transactions
    }
  }
  
  export const fetchTransactions = () =&gt; dispatch =&gt; axios.get('/api/transactions')
    .then(transactions =&gt; dispatch(fetchTransactionsSuccess(transactions)))
    .catch(err =&gt; dispatch(handleErr(err)))
  </code></pre>
  
  <p>And this is the test itself. Any help would be amazing. Been staring at this so long my eyes hurt.</p>
  
  <pre><code>import configureMockStore from 'redux-mock-store'
  import thunk from 'redux-thunk'
  import * as actions from '../../client/actions/actionCreators'
  import nock from 'nock'
  import expect from 'expect'
  
  const middlewares = [ thunk ]
  const mockStore = configureMockStore(middlewares)
  
  describe('async actions', () =&gt; {
    afterEach(() =&gt; {
      nock.cleanAll()
    })
  
    it('dispatches FETCH_TRANSACTIONS when data is returned', () =&gt; {
      nock('http://localhost:3000/')
        .get('/api/transactions')
        .reply(200, [
          {
            "_id": "588900efdf9d3e0905a2d604",
            "amount": 4.50,
            "name": "Cashew Nuts",
            "__v": 0,
            "date": "2017-01-25T00:00:00.000Z",
            "user": "58c2a33cc6cd5a5d15a8fc0c"
          },
          {
            "_id": "58890108df9d3e0905a2d605",
            "amount": 6.25,
            "name": "Monmouth Coffee",
            "__v": 0,
            "date": "2017-01-25T00:00:00.000Z",
            "user": "58c2a33cc6cd5a5d15a8fc0c"
          }
        ])
  
      const expectedActions = [
        {
          type: actions.FETCH_TRANSACTIONS,
          payload: [
            {
              "_id": "588900efdf9d3e0905a2d604",
              "amount": 4.50,
              "name": "Cashew Nuts",
              "__v": 0,
              "date": "2017-01-25T00:00:00.000Z",
              "user": "58c2a33cc6cd5a5d15a8fc0c"
            },
            {
              "_id": "58890108df9d3e0905a2d605",
              "amount": 6.25,
              "name": "Monmouth Coffee",
              "__v": 0,
              "date": "2017-01-25T00:00:00.000Z",
              "user": "58c2a33cc6cd5a5d15a8fc0c"
            }
          ]
        }
      ]
  
      const store = mockStore({ transactions: [] })
      console.log(actions)
      return store.dispatch(actions.fetchTransactions())
        .then(() =&gt; {
          expect(store.getActions()).toEqual(expectedActions)
        })
    })
  })
  </code></pre>
  
  <p>UPDATE
  The handleErr function returns setCurrentUser  which is another action (which the original action called with dispatch:</p>
  
  <pre><code>export function handleErr (err) {
    if (err.status === 401 || err.status === 404) {
      localStorage.removeItem('mm-jwtToken')
      setAuthToken(false)
      return setCurrentUser({})
    }
  }
  </code></pre>