Closed
Description
Current behavior
I've written the code below when fixing #16821.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/node_modules/jquery/dist/jquery.js"></script>
</head>
<body>
<button id="request">request</button>
<div id="result"></div>
<script type="text/javascript">
$(function(){
$("button#request").click(function(){
$.ajax({
method: "POST",
url: "/post-only",
data: JSON.stringify({client: 'data'})
})
.then((data) => {
$('#result').text(data)
})
})
})
</script>
</body>
</html>
it('works with reply', () => {
cy.intercept({
method: 'POST',
times: 1,
url: '/post-only',
},
(req) => {
req.reply('stubbed data')
}).as('interceptor')
cy.visit('fixtures/request.html')
cy.get('#request').click()
cy.get('#result').should('contain', 'stubbed data')
cy.get('#request').click()
cy.get('#result').should('contain', 'client') // Fail
})
But it failed because our times
counter only works with before:request
event. But reply
doesn't fire it and it only fires response
-related ones.
Desired behavior
The test should pass.
Test code to reproduce
See above.
Versions
Current Cypress 7.6.0