So say I've got a cypress test with a spy on window.fetch
like so:
describe('My test', () => {
beforeEach(() => {
cy.visit('http://localhost:3000', {
onBeforeLoad(win) {
cy.spy(win, 'fetch')
},
})
I can assert that POST request has a certain URL like so:
cy.window().its('fetch').should('be.calledWith', 'http://whatever.com/stuff')
but I can't figure out how to assert against the body of that request.
How would I assert, for instance, that it contains my_param=10
?
Thanks!
To extend the answer of @BaronVonKaneHoffen:
There is no need for extra import, you can use the Cypress.sinon.match.
Here is a snippet, for window.open stubbing if somebody would looking for it:
...
...
I think for fetch you can steal some ideas from it, too :).