-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
suggestion: mock global fetch
explicitly
#11779
suggestion: mock global fetch
explicitly
#11779
Conversation
|
@phryneas I really like this idea, and |
size-limit report 📦
|
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.
Really like the pattern of calling a method on the returned object, e.g. mockGlobal
, which then returns a disposable 🔥
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
This reverts commit 243c538.
* feat: accept min and max delay in createSchemaFetch * chore: add snapshot of invariant error and add tests * chore: update api reports and .size-limits.json * suggestion: mock global `fetch` explicitly * chore: update tests * chore: extract api * chore: update .size-limits.json * Clean up Prettier, Size-limit, and Api-Extractor --------- Co-authored-by: Alessia Bellisario <github@bellisar.io> Co-authored-by: alessbell <alessbell@users.n oreply.github.com>
@alessbell I'd love to hear your opinion on this:
It is just a thought that I just had when reviewing #11748 - should call
createSchemaFetch
always implicitly mockwindow.fetch
?That could cut down on the usability of the tool in some situations.
Instead, what I'd suggest would be a
mockGlobal
propery.So different usages might look like
or
While
would just return a
fetch
function that can be passed around, but won't pollute global scope.With that, using the plain object with
using
would end up with (at least?) a TS error:But once https://github.com/rbuckton/proposal-using-enforcement lands (it's suggested for stage 1/2 in todays TC39 meeting), we could make use of
[Symbol.enter]
to implicitly callmockGlobal
once it's used withusing
, so in the long term, the above code would work and mock global again.An alternative to that could be an option like
but I believe that might be a bit more clunky to handle.