I need to check that after the second click on the same button, an HTTP request is not sent. Is there a way to do it? I've already tried intercept and wait for this purpose, but can't make it work
I need to check that after the second click on the same button, an HTTP request is not sent. Is there a way to do it? I've already tried intercept and wait for this purpose, but can't make it work
A single-use intercept will probably work
const interceptOnce = (method, url, response) => {
let count = 0
return cy.intercept(method, url, req => {
count += 1
if (count < 2) {
req.reply(response)
} else {
throw 'Error: button click caused two requests' // cause test to fail
}
})
}
it('tests that two button clicks only sends a request on first click', () => {
interceptOnce('POST', myurl, {stubbed response object})
cy.get('button').click()
cy.get('button').click() // test fails here if a second request occurs
})
I'm not sure you even need to stub the response in this case.