Current behavior:
// this returns true
const callback = sinon.stub(window, 'fetch');
callback.withArgs(sinon.match.any).returns(true);
console.log(window.fetch('/api'));
// this never matches and serverStub is never called
cy.stub(win, 'fetch').withArgs(sinon.matches.any).callsFake(serverStub)
Desired behavior:
To be able to use withArgs the same way you would be able to as in sinon
How to reproduce:
see above
Test code:
import sinon from 'sinon';
const stub = {
'/api/v2/stub': { data: 'test stub' },
};
function responseStub(result) {
return {
text() {
return Promise.resolve(result);
},
ok: true,
};
}
Cypress.Commands.add('visitStubbed', (location, options = {}) => {
// this works as intended and console logs true
let callback = sinon.stub(window, 'fetch');
callback.withArgs(sinon.match.any).returns(true);
console.log(window.fetch('/api')); // Returns true
function serverStub(url, req) {
// this never gets called
const resultStub = stub[url];
if (resultStub) {
return Promise.resolve(responseStub(resultStub));
}
return fetch(url)
}
cy.visit(location, {
onBeforeLoad: (win) => {
cy.stub(win, 'fetch')
.withArgs(sinon.match.any)
.callsFake(serverStub);
win.fetch.callThrough();
},
})
})
Additional Info (images, stack traces, etc)
- Operating System: mac osx
- Cypress Version: 1.4.2
- Browser Version: 64
Current behavior:
Desired behavior:
To be able to use withArgs the same way you would be able to as in sinon
How to reproduce:
see above
Test code:
Additional Info (images, stack traces, etc)