title: Using Jest mocks results in "Actions must be plain objects. Use custom middleware for async actions."
body: <p>I have several Redux-Thunk-style functions that dispatch other actions in one file. One of these actions dispatches the other as part of its logic. It looks similar to this:</p>
  
  <pre><code>export const functionToMock = () =&gt; async (dispatch) =&gt; {
      await dispatch({ type: 'a basic action' });
  };
  
  export const functionToTest = () =&gt; async (dispatch) =&gt; {
      dispatch(functionToMock());
  };
  </code></pre>
  
  <p>In the case I'm actually running into, the functions are both much more involved and dispatch multiple action objects each. As a result, when I test my real-world <code>functionToTest</code>, I want to mock my real-world <code>functionToMock</code>. We already test <code>functionToMock</code> extensively, and I don't want to repeat the logic in those tests in <code>functionToTest</code>.</p>
  
  <p>However, when I try that, like so:</p>
  
  <pre><code>import configureMockStore from 'redux-mock-store';
  import thunk from 'redux-thunk';
  
  jest.mock('../exampleActions');
  const actions = require('../exampleActions');
  
  const mockStore = configureMockStore([thunk]);
  
  describe('example scenario showing my problem', () =&gt; {
      test('functionToTest dispatches fuctionToMock', () =&gt; {
          actions.functionToMock.mockReturnValue(() =&gt; Promise.resolve());
  
          const store = mockStore({});
  
          store.dispatch(actions.functionToTest());
  
          expect(actions.functionToMock.mock.calls.length).toBe(1);
      });
  });
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code> FAIL  test.js
    ● example scenario showing my problem › functionToTest dispatches fuctionToMock
  
      Actions must be plain objects. Use custom middleware for async actions.
          at Error (native)
  
        at dispatch (node_modules\redux-mock-store\dist\index-cjs.js:1:3137)
        at Object.dispatch (node_modules\redux-thunk\lib\index.js:14:16)
        at Object.&lt;anonymous&gt; (test.js:15:23)
  </code></pre>
  
  <p>(The example code I posted actually produces this error if you set them up in an environment with Jest, Redux, and Redux-Thunk. It is my <a href="https://stackoverflow.com/help/mcve">MVCE</a>.)</p>
  
  <p>One thought I had is that I can move the two functions into different files. Unfortunately, doing so would break pretty dramatically with how the rest of our project is organized, so I'm not willing to do that unless it is truly the only solution.</p>
  
  <p>How can I mock <code>functionToMock</code> in my tests for <code>functionToTest</code> without getting this error?</p>