-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fetch to global scope during Jest setup #30488
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Can you explain why you had to update whatwg-fetch
? I'd prefer to just make the code change to the Jest setup in this PR if possible.
v3 referenced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpojer has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
this is awesome thanks 🙏 |
It seems Libraries/Core/setUpXHR.js needs to be loaded for fetch to work properly. For example, fetch requires the |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR was closed because it has been stalled for 7 days with no activity. |
Summary
In the Jest documentation, the
react-native
preset in this repo is described as follows:However, while writing unit tests, I noticed that the Jest environment is missing a
fetch
implementation. According to the React Native docs, React Native includes a polyfill forfetch
. Putting these two statements together, it follows that there should be an implementation offetch
present in the Jest environment while testing.This PR adds a single line,
jest.requireActual('../Libraries/Network/fetch')
, to the Jest setup script. (As an alternative, I believe I could just userequire('whatwg-fetch')
, so if that's preferred please let me know and I'll update the PR.)Changelog
[General] [Fixed] - Added
fetch
to global scope during Jest testsTest Plan
I'm not sure if this change would require any updates to existing tests. If that's not the case, please let me know! As far as I can tell, there aren't any tests specific to the Jest preset.