title: Response for preflight has invalid HTTP status code 401 - Testing
body: <p>so i'm using nodejs to access an API ( league of legend api ) from my server, i tested the route that access the api using <code>httpie</code> ( a simple http client) and everything is working without any issue.</p>
  
  <p>when i wanted to write tests for my api using <code>Jest</code> + <code>supertest</code>, and when i tested the route that access the remote <code>LOL api</code>, a always get this error</p>
  
  <p><code>Response for preflight has invalid HTTP status code 401</code></p>
  
  <p>of course i never get this error when i'm using the http client or a webbrowser</p>
  
  <p><strong>Test Method</strong></p>
  
  <pre><code> test('exist route should return 200 if summoner exist', done =&gt; {
          request(app)
              .get('/summoners/exist/yaskillin')
              .expect('Content-Type', /json/)
              .expect(200)
              .then(res =&gt; {
                  expect(res.body.exist).toBeTruthy()
                  done()
              })
      })
  </code></pre>
  
  <p><strong>Route Method</strong></p>
  
  <pre><code>private exist(req: Request, res: Response, next: NextFunction) {
      let name: string = req.params["name"];
  
  
      return this.riotService
        .getSummonerByName(name)
        .then(result =&gt; {
            console.log(result)
            res.json({ exist: true });
        })
        .catch(err =&gt; {
            console.log(err.config)
            res.json({ exist: false });
        });
    }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
      Error: Error: Response for preflight has invalid HTTP status code 401
          at Object.dispatchError (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:65:19)
          at EventEmitter.client.on.err (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:664:20)
          at EventEmitter.emit (events.js:185:15)
          at Request.preflightClient.on.resp (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:373:16)
          at Request.emit (events.js:180:13)
          at Request.onRequestResponse (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/request/request.js:1068:10)
          at ClientRequest.emit (events.js:180:13)
          at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:539:21)
          at HTTPParser.parserOnHeadersComplete (_http_common.js:117:17)
          at TLSSocket.socketOnData (_http_client.js:444:20) undefined
  </code></pre>
  
  <p><strong>Error Object</strong></p>
  
  <pre><code>{ Error: Network Error
          at createError (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/axios/lib/core/createError.js:16:15)
          at XMLHttpRequest.handleError (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/axios/lib/adapters/xhr.js:87:14)
          at XMLHttpRequest.el.addEventListener.event (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/helpers/create-event-accessor.js:33:32)
          at invokeEventListeners (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
          at XMLHttpRequestEventTargetImpl._dispatch (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
          at XMLHttpRequestEventTargetImpl.dispatchEvent (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
          at XMLHttpRequest.dispatchEvent (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
          at requestErrorSteps (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:132:7)
          at Object.dispatchError (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:62:3)
          at EventEmitter.client.on.err (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:664:20)
          at EventEmitter.emit (events.js:185:15)
          at Request.preflightClient.on.resp (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:373:16)
          at Request.emit (events.js:180:13)
          at Request.onRequestResponse (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/request/request.js:1068:10)
          at ClientRequest.emit (events.js:180:13)
          at HTTPParser.parserOnIncomingClient (_http_client.js:539:21)
          at HTTPParser.parserOnHeadersComplete (_http_common.js:117:17)
          at TLSSocket.socketOnData (_http_client.js:444:20)
          at TLSSocket.emit (events.js:180:13)
          at addChunk (_stream_readable.js:269:12)
          at readableAddChunk (_stream_readable.js:256:11)
          at TLSSocket.Readable.push (_stream_readable.js:213:10)
          at TLSWrap.onread (net.js:581:20)
        config: 
         { adapter: [Function: xhrAdapter],
           transformRequest: { '0': [Function: transformRequest] },
           transformResponse: { '0': [Function: transformResponse] },
           timeout: 0,
           xsrfCookieName: 'XSRF-TOKEN',
           xsrfHeaderName: 'X-XSRF-TOKEN',
           maxContentLength: -1,
           validateStatus: [Function: validateStatus],
           headers: 
            { Accept: 'application/json, text/plain, */*',
              'Accept-Charset': 'application/x-www-form-urlencoded; charset=UTF-8',
              'X-Riot-Token': 'RGAPI-3467f48f-6e15-4bb2-8ebf-8d2acecac233',
              'Accept-Language': 'en-US,en;q=0.9,fr;q=0.8' },
           method: 'get',
           baseURL: 'https://euw1.api.riotgames.com/lol/',
           url: 'https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/yaskillin',
           data: undefined },
        request: 
         XMLHttpRequest {
           upload: XMLHttpRequestUpload { _ownerDocument: [Document] },
           _registeredHandlers: Set { 'readystatechange' },
           _eventHandlers: { readystatechange: [Function: handleLoad] },
           [Symbol(flag)]: 
            { synchronous: false,
              withCredentials: false,
              mimeType: null,
              auth: null,
              method: 'GET',
              responseType: '',
              requestHeaders: [Object],
              referrer: 'about:blank',
              uri: 'https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/yaskillin',
              timeout: 0,
              body: undefined,
              formData: false,
              preflight: true,
              requestManager: [RequestManager],
              pool: undefined,
              agentOptions: undefined,
              strictSSL: undefined,
              proxy: undefined,
              cookieJar: [CookieJar],
              encoding: 'UTF-8',
              origin: 'null',
              userAgent: 'Mozilla/5.0 (linux) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/11.6.2' },
           [Symbol(properties)]: 
            { beforeSend: false,
              send: false,
              timeoutStart: 0,
              timeoutId: 0,
              timeoutFn: null,
              client: [EventEmitter],
              responseHeaders: {},
              filteredResponseHeaders: [],
              responseBuffer: null,
              responseCache: null,
              responseTextCache: null,
              responseXMLCache: null,
              responseURL: '',
              readyState: 4,
              status: 0,
              statusText: '',
              error: Error: Response for preflight has invalid HTTP status code 401
          at Request.preflightClient.on.resp (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:373:30)
          at Request.emit (events.js:180:13)
          at Request.onRequestResponse (/home/ssd/Dev/Project/lolnafrica/backend/node_modules/request/request.js:1068:10)
          at ClientRequest.emit (events.js:180:13)
          at HTTPParser.parserOnIncomingClient (_http_client.js:539:21)
          at HTTPParser.parserOnHeadersComplete (_http_common.js:117:17)
          at TLSSocket.socketOnData (_http_client.js:444:20)
          at TLSSocket.emit (events.js:180:13)
          at addChunk (_stream_readable.js:269:12)
          at readableAddChunk (_stream_readable.js:256:11),
              uploadComplete: true,
              uploadListener: false,
              abortError: false,
              cookieJar: [CookieJar],
              bufferStepSize: 1048576,
              totalReceivedChunkSize: 0,
              requestBuffer: null,
              requestCache: null,
              origin: 'null' } },
        response: undefined }
  </code></pre>