unfetch icon indicating copy to clipboard operation
unfetch copied to clipboard

Add polyfill/support for Request

Open studentIvan opened this issue 7 years ago • 2 comments

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

studentIvan avatar Sep 14 '18 19:09 studentIvan

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.

developit avatar Sep 17 '18 14:09 developit

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.

Gelio avatar Jan 21 '22 12:01 Gelio