Hi - it sounds like your test is making real requests - which means the fakeServer did not catch it. it could be a lot of things but the most likely explaination is the url in the setup is wrong.
could you try using a regex instead of a string for respondWith setup? could you share what you have?
yea I looked into it and I think you are right for the first part.
However I don't think it's incompatibility issue between jest / sinon.
Since jest runs the code in the node environment, not all browser native functions are properly implemented. If you are using fetch - some polyfill libraries work correctly with sinon (e.g. whatwg-fetch), while others don't (e.g. isomorphic-fetch). sinon's fakeServer also does not work with axios correctly if you are using that.
The error you are getting indicates the fake server is not mocking the correct fetch (or XMLHttpRequest) - real requests are being made in the test environment - maybe it's better to investigate how you can mock the request library/method you are using directly with jest.
Hi - it sounds like your test is making real requests - which means the fakeServer did not catch it. it could be a lot of things but the most likely explaination is the
url
in the setup is wrong.could you try using a regex instead of a string for
respondWith
setup? could you share what you have?Sinon’s fake server doesn’t fall back to real requests. The issue is possibly that the current versions of sinon and jest are incompatible.
yea I looked into it and I think you are right for the first part.
However I don't think it's incompatibility issue between jest / sinon.
Since
jest
runs the code in the node environment, not all browser native functions are properly implemented. If you are usingfetch
- some polyfill libraries work correctly with sinon (e.g.whatwg-fetch
), while others don't (e.g.isomorphic-fetch
). sinon's fakeServer also does not work withaxios
correctly if you are using that.The error you are getting indicates the fake server is not mocking the correct
fetch
(orXMLHttpRequest
) - real requests are being made in the test environment - maybe it's better to investigate how you can mock the request library/method you are using directly withjest
.Yeah, I gave up and mocked my endpoint functions, which are a simple layer atop superagent, which uses XHR.