cy.intercept not breaking if request object is wrong
See original GitHub issueHello,
I want to test that an outgoing request has the correct body. I saw in the documentation that you can do it like this.
describe('Check Marketing logging', () => {
before(function () {
cy.visit('https://www.independer.nl/zorgverzekering/intro.aspx');
});
it('Check button click - intercept req', function () {
const requestBody = { "wrong": "request body" };
cy.intercept('POST', '/api/ue/c', (req) => {
expect(JSON.stringify(req.body)).to.include(JSON.stringify(requestBody));
}).as('sLIdentifier');
cy.getByUe('man', 'input').click({ force: true });
cy.wait('@sLIdentifier');
});
});
The only thing is if the condition is right or wrong the runner always shows succeded. See image below.
It feels like this is a bug. The workarround I have now it doing it on the wait like this.
it('Check button click - intercept wait', function () {
const requestBody = { "wrong": "request body" };
cy.intercept('POST', '/api/ue/c').as('sLIdentifier');
cy.getByUe('vrouw', 'input').click({ force: true });
cy.wait('@sLIdentifier').should(({ request }) => {
expect(JSON.stringify(request.body)).to.include(JSON.stringify(requestBody));
})
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Cypress cy.intercept Problems - Gleb Bahmutov
Use specific intercepts and make sure the stubs are not "breaking" any listeners defined afterwards. Change the first intercept to only work ...
Read more >intercept - Cypress Documentation
cy.intercept can be used solely for spying: to passively listen for matching routes and apply aliases to them without manipulating the request or...
Read more >Having trouble asserting on requests using cy.intercept. 'cy.its ...
All is good upto verfying the status code then it breaks. This is the error thrown: Timed out retrying: cy.its() errored because the...
Read more >A Practical Guide to Intercepting Network Requests in Cypress
In this article, I'd like to walk you through some of the capabilities of Cypress' .intercept() command. It is a super useful tool,...
Read more >cypress-io/cypress - Gitter
I'm trying to use the new cy.intercept for GraphQL responses. I do not want to stub or mock. I simply want to grab...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah I found the issue. We are using a Cypress Helper package with custom function etc. But in there this code was placed
So when I removed this code it works fine. Don’t know why we put this code here the first place 😦
Thanks for the help.
I cannot recreate this problem with Cypress v6.3.0 using https://github.com/cypress-io/cypress-test-tiny/tree/intercept-issue-14671