I am testing search functionality in one of my Cypress tests and having trouble getting to all parts of the request url. On my page, I have a form that a user can enter a number to search for. When a user clicks "Search", the system makes an ajax request with the appropriate data. Everything is working great.
In my Cypress test, I'm intercepting a GET
request in one of my tests like this:
cy.intercept('GET', '/api/v1/foo/?include=**').as('myRequest');
...
That is the GET
request that is made when a user clicks the submit button to search.
Within my test, I am entering text into a text field like this:
...
cy.get('[data-cy="number"]').type('12345');
The text is getting properly interred into the input. Next, I am triggering an ajax request like this:
...
cy.get('[data-cy="search"]').should('exist').click();
cy.wait('@myRequest').then((interception) => {
console.log(interception.request.url); // /api/v1/forms/?include=foo <-- does not have filter[number]...
expect(interception.request.url).to
.include('filter[number]=12345');
});
When submitting a real request (not through cypress) the request url looks like this:
https://example.com/api/v1/foo/?include=bar&filter[number]=12345
However, when cypress makes the request, it's seemingly not picking up the query field and my test is failing.
I've also tried using expect(interception.request.query)
but it is always undefined
.
How can I properly pick up the filter[number]
query param in my test?