title: Testing Async Redux Action Jest
body: <p>I'm having trouble getting the correct output from an async redux action.  I am using Jest, redux-mock-adapter, and thunk as the tools.</p>
  
  <p>According to redux's documentation on testing async thunks (<a href="https://redux.js.org/docs/recipes/WritingTests.html#async-action-creators" rel="nofollow noreferrer">https://redux.js.org/docs/recipes/WritingTests.html#async-action-creators</a>), my tests should be returning an array of two actions.  However, my test is only returning the first action, and not the second one that should return on a successful fetch.  I think I'm just missing something small here, but it has been bothersome to say the least.</p>
  
  <p><strong>Redux Action</strong></p>
  
  <pre><code>export const getRemoveFileMetrics = cacheKey =&gt; dispatch =&gt; {
      dispatch({ type: IS_FETCHING_DELETE_METRICS });
      return axios
          .get("GetRemoveFileMetrics", { params: { cacheKey } })
          .then(response =&gt; dispatch({ type: GET_REMOVE_FILE_METRICS, payload: response.data }))
          .catch(err =&gt; err);
  };
  </code></pre>
  
  <p><strong>Test</strong></p>
  
  <pre><code>it("getRemoveFileMetrics() should dispatch GET_REMOVE_FILE_METRICS on successful fetch", () =&gt; {
          const store = mockStore({});
          const cacheKey = "abc123doremi";
          const removeFileMetrics = {
              cacheKey,
              duplicateFileCount: 3,
              uniqueFileCount: 12,
          };
          const expectedActions = [
              {
                  type: MOA.IS_FETCHING_DELETE_METRICS,
              },
              {
                  type: MOA.GET_REMOVE_FILE_METRICS,
                  payload: removeFileMetrics,
              }
          ];
          mockRequest.onGet(`/GetRemoveFileMetrics?cacheKey=${cacheKey}`).reply(200, removeFileMetrics);
          return store.dispatch(MOA.getRemoveFileMetrics(cacheKey)).then(() =&gt; {
              const returnedActions = store.getActions();
              expect(returnedActions).toEqual(expectedActions);
          });
      });
  </code></pre>
  
  <p><strong>The Output</strong></p>
  
  <pre><code>Expected value to equal:
      [{ "type": "IS_FETCHING_DELETE_METRICS" }, { "payload": { "cacheKey": "abc123doremi", "duplicateFileCount": 3, "uniqueFileCount": 12 }, "type": "GET_REMOVE_FILE_METRICS" }]
  Received:
      [{ "type": "IS_FETCHING_DELETE_METRICS" }]
  </code></pre>