title: Testing async actions with redux thunk
body: <p></p>
  
  <p>I am trying to test my action which has an async call. I use Thunk as my middleware. In the action below, I only dispatch and update the store if the server returns an <code>OK</code> response.</p>
  
  <pre class="lang-js prettyprint-override"><code>export const SET_SUBSCRIBED = 'SET_SUBSCRIBED'
  
  export const setSubscribed = (subscribed) =&gt; {
    return function(dispatch) {
      var url = 'https://api.github.com/users/1/repos';
  
      return fetch(url, {method: 'GET'})
        .then(function(result) {
          if (result.status === 200) {
            dispatch({
              type: SET_SUBSCRIBED,
              subscribed: subscribed
            })
            return 'result'
          }
          return 'failed' //todo
        }, function(error) {
          return 'error'
        })
    }
  }
  </code></pre>
  
  <p>I am having trouble writing tests to either tests that dispatch either gets called or doesn't (depending on server response) or I could just let the action get called and check that the value in the store is updated correctly.</p>
  
  <p>I am using fetch-mock to mock the web's fetch() implementation. However, it looks like the block of my code in <code>then</code> does not execute. I have also tried using the example here with no luck - <a href="http://redux.js.org/docs/recipes/WritingTests.html" rel="noreferrer">http://redux.js.org/docs/recipes/WritingTests.html</a></p>
  
  <pre class="lang-js prettyprint-override"><code>const middlewares = [ thunk ]
  const mockStore = configureStore(middlewares)
  
  //passing test
  it('returns SET_SUBSCRIBED type and subscribed true', () =&gt; {
    fetchMock.get('https://api.github.com/users/1/repos', { status: 200 })
  
    const subscribed = { type: 'SET_SUBSCRIBED', subscribed: true }
    const store = mockStore({})
  
    store.dispatch(subscribed)
  
    const actions = store.getActions()
  
    expect(actions).toEqual([subscribed])
    fetchMock.restore()
  })
  
  //failing test
  it('does nothing', () =&gt; {
    fetchMock.get('https://api.github.com/users/1/repos', { status: 400 })
  
    const subscribed = { type: 'SET_SUBSCRIBED', subscribed: true }
    const store = mockStore({})
  
    store.dispatch(subscribed)
  
    const actions = store.getActions()
  
    expect(actions).toEqual([])
    fetchMock.restore()
  })
  </code></pre>
  
  <p>After looking into this some more, I believe there is something wrong with fetch-mock either not resolving the promise so that the then statements execute or it's completely stubbing out fetch. When I add a console.log to both then statements, nothing executes.</p>
  
  <p><strong>What am I doing incorrectly in my tests?</strong></p>