unfetch
unfetch copied to clipboard
Add polyfill/support for Request
If I use Request, I also can set headers, method, etc and work with it. https://developer.mozilla.org/en-US/docs/Web/API/Request
I was originally against this since it's impossible to do in 500b, but I think we need a solution. Perhaps shipping the JS Modules build with { fetch, Request, Response, Headers, AbortController } as exports would promote correct usage.
My use case was trying to use isomorphic-unfetch in jest tests running in Node. Since fetch was not globally set, isomorphic-unfetch used the one from node-fetch and fetching was working fine. The problem appeared I hit new Request(...) in my tests. Request was not globally available in Node, which threw an error.
I ended up polyfilling those globally-available fetch-related symbols using the method suggested in https://github.com/node-fetch/node-fetch#providing-global-access in my jest-setup.js.
I'm sharing just in case someone is also looking for a solution how to get those globals to work in jest.