// 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