Created
January 3, 2019 17:25
-
-
Save jbinto/8bd7cc874e503bdd132b2198e3141485 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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