thankful-wire-37848
02/21/2023, 9:46 AMcy.intercept routeMatcher works. The docs aren't very specific but it seems that if you use strings there, they will do partial/wildcard/contains matching and not exact string matching. The reason I'm asking is because I'm testing a suggestion feature with two filter fields (first-name and last-name). Changing each field will trigger a call to the suggestion API (actually while typing but cy.type is fast enough to only trigger it once per field) which I need to intercept. I tried using this code (simplified):
const pathname = `/suggestions`
cy.intercept({
pathname,
query: {
first_name: 'John',
last_name: '',
},
}).as('first-name-search')
cy.intercept({
pathname,
query: {
first_name: 'John',
last_name: 'Doe',
},
}).as('last-name-search')
cy.get('input[name=first_name]').type('John')
cy.wait('@first-name-search')
cy.get('input[name=last_name]').type('Doe')
cy.wait('@last-name-search')
... but then the first-name-search intercepts both API calls and the empty last_name query property seems to match twice. So even though there are only 2 API calls, I get three matches in the routes panel.
I can't really use a URL string matcher here as the API library sometimes messes with the query param order. The only thing that got it working for me is to replace the empty string with a very restrictive Regex: /^$/. Is there no better way than this?nutritious-honey-65632
02/21/2023, 6:05 PM