title: Unable to write Redux tests for action creators
body: <p><strong>ORIGINAL QUESTION</strong></p>
  
  <p>I'm following the example for writing tests for async action creators spelled out in the <a href="http://redux.js.org/docs/recipes/WritingTests.html#async-action-creators]" rel="nofollow noreferrer">Redux documentation</a>. I'm following the example as closely as possible, but I can't get the test to work. I'm getting the following error message:</p>
  
  <pre><code>   TypeError: Cannot read property 'then' of undefined
     (node:789) UnhandledPromiseRejectionWarning: Unhandled promise rejection 
     (rejection id: 28): TypeError: Cannot read property 'data' of undefined
  </code></pre>
  
  <p>Here is the code for my action creator and test:</p>
  
  <p>actions/index.js</p>
  
  <pre><code>import axios from 'axios';
  import { browserHistory } from 'react-router';
  import { AUTH_USER, AUTH_ERROR, RESET_AUTH_ERROR } from './types';
  
  const API_HOST = process.env.NODE_ENV == 'production'
                  ? http://production-server
                  : 'http://localhost:3090';
  
  export function activateUser(token) {
    return function(dispatch) {
      axios.put(`${API_HOST}/activations/${token}`)
        .then(response =&gt; {
          dispatch({ type: AUTH_USER });
  
          localStorage.setItem('token', response.data.token);
        })
        .catch(error =&gt; {
          dispatch(authError(error.response.data.error));
        });
    }
  }
  
  export function authError(error) {
    return {
      type: AUTH_ERROR,
      payload: error
    }
  }
  </code></pre>
  
  <p>confirmation_test.js</p>
  
  <pre><code>import configureMockStore from 'redux-mock-store'; 
  import thunk from 'redux-thunk';
  import * as actions from '../../src/actions';
  import { AUTH_USER, AUTH_ERROR, RESET_AUTH_ERROR } from 
  '../../src/actions/types';
  import nock from 'nock';
  import { expect } from 'chai';
  
  const middlewares = [ thunk ];
  const mockStore = configureMockStore(middlewares);
  
  describe('Confirmation_Token action creator', () =&gt; {
    afterEach(() =&gt; {
      nock.cleanAll()
    });
  
    it('dispatches AUTH_USER', (done) =&gt; {
      nock('http://localhost:3090')
      .put('/activations/123456')
      .reply(200, {
          token: 7891011
      });
  
      const expectedActions = { type: AUTH_USER };
  
      const store = mockStore({});
  
      return store.dispatch(actions.activateUser(123456))
       .then(() =&gt; { // return of async actions
         expect(store.getActions()).toEqual(expectedActions);
         done();
       });
    });
  });
  </code></pre>
  
  <p><strong>UPDATED QUESTION</strong></p>
  
  <p>I've partially (though not entirely) figured this out. I got this to work by adding a <code>return</code> statement in front of <code>axios</code> and commenting out the <code>localstorage.setItem</code> call. </p>
  
  <p>I also turned the object I assigned to <code>expectedActions</code> to an array, and changed my assertion from <code>toEqual</code> to <code>to.deep.equal</code>. Here is the modified code:</p>
  
  <p>actions/index.js</p>
  
  <pre><code>export function activateUser(token) {
    return function(dispatch) { // added return statement
      return axios.put(`${API_HOST}/activations/${token}`)
        .then(response =&gt; {
          dispatch({ type: AUTH_USER });
          // localStorage.setItem('token', response.data.token); Had to comment out local storage
        })
        .catch(error =&gt; {
          dispatch(authError(error.response.data.error));
        });
    }
  }
  </code></pre>
  
  <p>confirmation_test.js</p>
  
  <pre><code>describe('ConfirmationToken action creator', () =&gt; {
    afterEach(() =&gt; {
       nock.cleanAll()
    });
  
    it('dispatches AUTH_USER', (done) =&gt; {
      nock('http://localhost:3090')
      .put('/activations/123456')
      .reply(200, {
          token: 7891011
       });
  
      const expectedActions = [{ type: AUTH_USER }];
  
      const store = mockStore({});
  
      return store.dispatch(actions.activateUser(123456))
       .then(() =&gt; { // return of async actions
         expect(store.getActions()).to.deep.equal(expectedActions);
         done();
       });
     });
   });
  </code></pre>
  
  <p>But now I can't test <code>localStorage.setItem</code> without producing this error message:</p>
  
  <pre><code>Error: timeout of 2000ms exceeded. Ensure the done() callback is being called 
  in this test.
  </code></pre>
  
  <p>Is this because I need to mock out <code>localStorage.setItem</code>? Or is there an easier solve that I'm missing?</p>