javascript - Testing XHR with Jest -


i have simple test case:

describe ('request', function () {   ('should perform xhr "get" request', function (done) {     var xhr = new xmlhttprequest;      xhr.open('get', 'http://google.com', true);     xhr.send();   }); }); 

the point is: when jest in terminal, seems it's not requesting http://google.com. think happening because jest uses jsdom under hood , haven't capability reproduce http request out of browser itself.

suggestions?

note: errors appearing, test passing, request isn't being made.

there're number of problems:

  1. in code example don't create instance of xmlhttprequest. should this: var xhr = new xmlhttprequest()
  2. making real requests in tests bad idea. if module depends on data remote server should mock xmlhttpsrequest or use "fake server" (e.g. sinon). recommend don't make real requests in tests.

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -