implement `window.fetch` capturing/mocking
See original GitHub issueMany developers are migrating to window.fetch
from XHRs due to the simplified async interface it exposes. I happen to be one of those developers.
Cypress should support window.fetch
with similar abilities to those of XHRs: I should be able to query the request and response, wait on them, and mock with data and fixtures.
Cypress team edit
This feature will work seamlessly once Full network stubbing is implemented.
Workarounds
- use experimental fetch polyfill available in v4.9.0
or do it yourself:
- delete
window.fetch
before visiting the page to force your application to polyfill it on top of XHR. If the application does not include a polyfill, you can load one from your tests. - stub
window.fetch
directly in JavaScript
See these solutions in Stubbing window.fetch
example recipe
Issue Analytics
- State:
- Created 8 years ago
- Reactions:502
- Comments:119 (15 by maintainers)
Top Results From Across the Web
Using the Fetch API - MDN Web Docs
Here we are fetching a JSON file across the network and printing it to the console. The simplest use of fetch() takes one...
Read more >Introduction to fetch() - web.dev
The fetch() API is landing in the window object and is looking to replace XHRs.
Read more >Intercepting JavaScript Fetch API requests and responses
We demonstrate intercepting JavaScript Fetch API calls using monkey patching and the fetch-intercept library.
Read more >window-fetch - npm
Instead of implementing XMLHttpRequest in Node.js to run browser-specific Fetch polyfill, why not go from native http to fetch API directly?
Read more >How to Use the Fetch API (Correctly) - CODE Magazine
html file and at the bottom of the page, modify the window.onload function to look like the following code snippet. You're building a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
@brian-mann worked like a charm! I just put this in
support/index.js
:Guys, please prioritize this task… it’s open since 2016! In 2020 the entire world use
fetch
!