Skip to content

Instantly share code, notes, and snippets.

@jbinto
Created January 3, 2019 17:25
Show Gist options
  • Save jbinto/8bd7cc874e503bdd132b2198e3141485 to your computer and use it in GitHub Desktop.
Save jbinto/8bd7cc874e503bdd132b2198e3141485 to your computer and use it in GitHub Desktop.
// option 1 to override fetch, using cypress built-in facilities (e.g. sinon)
cy
// sinon syntax ⬇️
.stub(win, 'fetch')
.withArgs('/graphql')
// The pseudocode-ish that this generates, kinda like this:
const realFetch = window.fetch
window.fetch = (arg1) => {
if (arg1 === '/grapqhl') {
doFakeStuff()
}
else {
return realFetch(arg1)
}
}
// option 2 to override fetch (again pseudocode)
// seems like this is necessary since sinon2.0 because of the "thennable" issue
myFakeFetch = {
// whatever...
}
cy.window(win => {
win.fetch = myFakeFetch
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment