jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
881 stars 116 forks source link

Apollo Server 3 Support #216

Closed dchambers closed 2 years ago

dchambers commented 2 years ago

Apollo Server 3 changed the type definitions it uses for the Fetch API. The Request object it now uses can no longer be identified using instanceof Request, breaking jest-fetch-mock in the case where Request objects are being passed. This can be mitigated by identifying using the name of the class used to construct the Request object, which works in both cases.

The first commit tests the status quo, while the second commit enables support for Apollo Server 3.

yinzara commented 2 years ago

While I appreciate your want for this library to support your use case, we use the cross-fetch library specifically so we don't have to deal with the differences in the fetch APIs for different environments.

Additionally, I don't think this will actually work. While the test cases may pass, the mock library is not overriding the fetch API provided by apollo-server.

We use the cross-fetch dependency to isolate us from the differences in the fetch API between different environments (like the browser, NodeJS and React).

That library already has support for React Native, maybe you could convince those library maintainers to support adding Apollo server to support it. Then we could support it by just using the latest of cross-fetch.

dchambers commented 2 years ago

So it turns out that a fix for this already exists on master, but it's just not been released yet:

This problem can be mitigated by updating the version specifier for jefflau/jest-fetch-mock in your project's pacakge.json from ^3.0.3 to jefflau/jest-fetch-mock#master.