Closed dchambers closed 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
.
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
.
Apollo Server 3 changed the type definitions it uses for the Fetch API. The
Request
object it now uses can no longer be identified usinginstanceof Request
, breakingjest-fetch-mock
in the case whereRequest
objects are being passed. This can be mitigated by identifying using the name of the class used to construct theRequest
object, which works in both cases.The first commit tests the status quo, while the second commit enables support for Apollo Server 3.