Skip to content

Cypress JS, is there anyway to ignore some of the network Pending calls

Hi currently using cypress automation framework , when I visit the home page cy.visit('/'); some icons are missing and I pretty much don’t care much about their existence since I am working in dev env. But cypress wont go to next step till either the status of those network calls changes to failed or cypress times out. Either way it fails. I was wondering if there is anyway to force cypress to ignore certain pending calls ?

these are the Pending network status

Answer

You can use command cy.intercept() to stub a response for targeted calls.

cy.intercept('GET', '**/favicon.ico', { fixture: 'cat.png' });

So every calls to favicon.ico will immediately return anything you specify instead of waiting for the call to receive an answer. In my example, it will return a png of a cat I previously copied to my fixtures folder in cypress/integration/fixtures.