title: Redux Promise Middleware + Redux Mock Store Testing
body: <p>I tried to test an action creator that returns a promise, using also redux mock store.</p>
  
  <pre><code>import promiseMiddleware from 'redux-promise-middleware';
  import nock from 'nock';
  import configureStore from 'redux-mock-store';
  import { domain, port } from '../../config/environment';
  
  import { GET_ITEMS_START,
           GET_ITEMS_SUCCESS } from '../../constants/items';
  import { getItems } from './items';
  
  const promise = promiseMiddleware({
    promiseTypeSuffixes: ['START', 'SUCCESS', 'ERROR']
  });
  
  describe('Get Items', () =&gt; {
      it('should create GET_ITEMS_SUCCESS action after successfully getting items', (done) =&gt; {
        nock(`${domain}:${port}`)
          .get('/api/items')
          .reply(200, {
            _id: '1',
            text: 'Make Eggs',
            completed: false
          });
  
        const expectedActions = [
          { type: GET_ITEMS_START },
          { type: GET_ITEMS_SUCCESS, payload: {
            data: {  _id: '1', text: 'Make Eggs', completed: false }
          }}
        ];
  
        const store = mockStore({}, expectedActions, done);
        store.dispatch(getItems());
      });
    });
  </code></pre>
  
  <p>and here is my action creator code</p>
  
  <pre><code>export function getItems() {
    return {
      type: GET_ITEMS,
      payload: {
        promise: axios.get(`${domain}:${port}/api/items`)
      }
    };
  }
  </code></pre>
  
  <p>but the result is mismatch because the promise resolved a deep nested objects</p>
  
  <pre><code>  Error: Expected { payload: { config: { headers: {}, method: 'get', timeout: 0, transformRequest: [ [Function] ], transformResponse: [ [Function] ], url: 'http://localhost:3000/api/items', withCredentials: undefined }, data: { _id: '1', completed: false, text: 'Make Eggs' }, headers: {}, status: 200, statusText: 'OK' }, type: 'GET_ITEMS_SUCCESS' } to equal { payload: { data: { _id: '1', completed: false, text: 'Make Eggs' } }, type: 'GET_ITEMS_SUCCESS' }
    + expected - actual
  
     {
       "payload": {
    -    "config": {
    -      "headers": {}
    -      "method": "get"
    -      "timeout": 0
    -      "transformRequest": [
    -        [Function]
    -      ]
    -      "transformResponse": [
    -        [Function]
    -      ]
    -      "url": "http://localhost:3000/api/items"
    -      "withCredentials": [undefined]
    -    }
         "data": {
           "_id": "1"
           "completed": false
           "text": "Make Eggs"
         }
    -    "headers": {}
    -    "status": 200
    -    "statusText": "OK"
       }
       "type": "GET_ITEMS_SUCCESS"
     }
  </code></pre>
  
  <p>I obviously don't want to copy all of those deep nested properties into my test suite. </p>
  
  <p>Is there a better way of doing this?</p>