title: CORS error - Error: Cross origin http://localhost forbidden - in ReactJS/Jest test only
body: <p>I'm running into a problem where the request I am making to an outside API is working fine in execution, but when runing a Jest/Enzyme test it gives me a CORS error. The function in question is using a JsonRpc implementation from an API, and using fetch from node-fetch. Not sure if there are settings for CORS I can apply somewhere?</p>
  
  <p>I tried many variations of async waits in Jest/Enzyme testing framework but am still running into issues.</p>
  
  <pre><code>test("it should do something", done =&gt; {
      const component = shallow(&lt;CustomComponent /&gt;)
      component.instance().customAsyncFunction( result =&gt; {
        expect(result.length).toEqual(5)
        done()
      })
      // return component.instance().customAsyncFunction().then(data =&gt; {
      //   expect(data.length).toEqual(5)
      // })
    })
  </code></pre>
  
  <p>I tried the above and a few other methods (like setTimeout and awaiting it) and get the CORS error.</p>
  
  <p>The results I'm getting are:</p>
  
  <pre><code> console.error
   node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29
     Error: Cross origin http://localhost forbidden
         at dispatchError (...\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\living\xhr-utils.js:65:19)
         at Request.client.on.res (...\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\living\xmlhttprequest.js:679:38)
         at Request.emit (events.js:198:13)
         at Request.onRequestResponse (...\node_modules\request\request.js:1066:10)
         at ClientRequest.emit (events.js:203:15)
         at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
         at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
         at TLSSocket.socketOnData (_http_client.js:442:20) undefined
  </code></pre>
  
  <p>Any ideas?</p>