title: Testing dispatched actions in Redux thunk with Jest
body: <p>I'm quite new to Jest and admittedly am no expert at testing async code... </p>
  
  <p>I have a simple <code>Fetch</code> helper I use:</p>
  
  <pre><code>export function fetchHelper(url, opts) {
      return fetch(url, options)
          .then((response) =&gt; {
              if (response.ok) {
                  return Promise.resolve(response);
              }
  
              const error = new Error(response.statusText || response.status);
              error.response = response;
  
              return Promise.reject(error);
          });
      }
  </code></pre>
  
  <p>And implement it like so:</p>
  
  <pre><code>export function getSomeData() {
      return (dispatch) =&gt; {
          return fetchHelper('http://datasource.com/').then((res) =&gt; {
              dispatch(setLoading(true));
              return res.json();
          }).then((data) =&gt; {
              dispatch(setData(data));
              dispatch(setLoading(false));
          }).catch(() =&gt; {
              dispatch(setFail());
              dispatch(setLoading(false));
          });
      };
  }
  </code></pre>
  
  <p>However I want to test that the correct dispatches are fired in the correct circumstances and in the correct order.</p>
  
  <p>This used to be quite easy with a <code>sinon.spy()</code>, but I can't quite figure out how to replicate this in Jest. Ideally I'd like my test to look something like this:</p>
  
  <pre><code>expect(spy.args[0][0]).toBe({
    type: SET_LOADING_STATE,
    value: true,
  });
  
  
  expect(spy.args[1][0]).toBe({
    type: SET_DATA,
    value: {...},
  });
  </code></pre>
  
  <p>Thanks in advance for any help or advice!</p>