Nock is not intercepting API call in Redux test
<p>I'm trying to test an api call in a redux app. The code pretty much follows the pattern outlined in the <em>Async Action Creators</em> section of the redux docs:</p>

<p><a href="http://redux.js.org/docs/recipes/WritingTests.html">http://redux.js.org/docs/recipes/WritingTests.html</a></p>

<p>The gist of it is that you use <em>redux-mock-store</em> to record and assert against any actions that are triggered.</p>

<p>This is the whole test, using nock to mock the api call:</p>

<pre><code>import React from 'React'
import ReactDOM from 'react-dom'
import expect from 'expect';
import expectJSX from 'expect-jsx';
import TestUtils from 'react-addons-test-utils'
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import nock from 'nock'
expect.extend(expectJSX);

import * as types from '../../constants/Actions'

describe('Async Search Actions', () =&gt; {
    const thunkMiddleware = [ thunk ];
     /* use redux-mock-store here */
    const mockStore = configureMockStore(thunkMiddleware);


    describe('The fetchArtistData action creator should', () =&gt; {

            afterEach(() =&gt; {
                nock.cleanAll()
            })

        it('Should fire off a ARTIST action when fetch is done', (done) =&gt; {
            nock('http://ws.audioscrobbler.com')
                .get('/2.0/')
                .query({method: 'artist.search', artist: 'ho', api_key: 'abc123', format: 'json', limit: 5})
                .reply(200, 
                      {
                        fake: true
                      }
                   )



            const expectedActions = [
                { type: types.ARTIST, artists: {
                        fake: true
                    } 
                }
            ];

            let store = mockStore([], expectedActions, done);
            store.dispatch(fetchArtist('ho'))

        });

    });

});
</code></pre>

<p>But it seems that the real lastFm api is called when the test is run...real data is returned from lastFm rather than the fake nock response.</p>

<p>This is the action creator itself:</p>

<pre><code>export function fetchArtist(search) {
    return dispatch =&gt; {
        return fetch(`http://ws.audioscrobbler.com/2.0/?method=artist.search&amp;artist=${search}&amp;api_key=abc123&amp;format=json&amp;limit=5`)
            .then(handleErrors)
            .then(response =&gt; response.json())
            .then(json =&gt; { dispatch(ArtistData(searchTerm, json)) })
            .catch(handleServerErrors)
    }
}
</code></pre>

<p>The assertion fails because the live lastFM response is not the same as the response I'm expecting as per the <code>expectedActions</code> object..</p>

<p>I've tried assigning the nock to a variable and log it out.The log shows this:</p>

<p>Nock seems to be adding port 80 to the url, not sure if this is causing the actual API to not be mocked:</p>

<pre><code>    keyedInterceptors: Object{GET http://ws.audioscrobbler.com:80/2.0/?
method=artist.search&amp;artist=john&amp;api_key=abc123&amp;format=json&amp;limit=5
</code></pre>

<p>Any ideas what's wrong here?</p>