Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress intercept - No request ever occurred

Tags:

cypress

On clicking a checkbox, a GET request will get triggered in my application.

I am trying to validate this with cypress but it throws 'Timed out retrying after 30000ms: cy.wait() timed out waiting 30000ms for the 1st request to the route: getGridWind10M. No request ever occurred.'

My code:

cy.intercept("GET", "v1/kml/F20210903120000/Wind10M?view=grid*").as('getGridWind10M');
cy.get('[data-test="ckbx-w10m"]')
    .check({ force: true }) 
    .should("be.checked"); 
cy.wait('@getGridWind10M').its('response.statusCode').should('eq', 200)

Actual Endpoint:

https://domain/path/api/v1/kml/F20210903120000/Wind50M?view=grid&time=2021-09-03T14:00:00.000Z&z=3&x=5&y=4

Test Log:

enter image description here

enter image description here

I have tried the following with no luck. Someone please help me to find out where and what am I missing here as the request in successfully completed as shown in the image?

cy.intercept("GET", "*/F20210903120000/Wind10M?view=grid*").as('getGridWind10M');
cy.intercept("GET", "*F20210903120000/Wind10M?view=grid&*").as('getGridWind10M');
cy.intercept("GET", "*F20210903120000/Wind10M?view=grid*").as('getGridWind10M');
cy.intercept("GET", "/F20210903120000/Wind10M?view=grid*").as('getGridWind10M');
like image 827
Dhamo Avatar asked Feb 25 '26 02:02

Dhamo


1 Answers

You can catch it with a leading ** meaning multiple preceding parts, and a trailing ?* meaning has some search params.

const url = "**/v1/kml/F20210903120000/Wind10M?*"
cy.intercept('GET',url, {}).as('getGridWind10M')    // stubbing here
cy.get('checkbox').check()
cy.wait('@getGridWind10M')

I note there is a difference in the actual endpoint Wind50M and the intercepted endpoint Wind10M, probably a typo?

This also works if you are wilcarding middle path segments

const url =  "**/v1/kml/*/Wind10M?*"

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!