Why is Cypress not using this stubbed route?

Viewed 133

I'm stubbing the following:

  cy.route("GET", "**/api/v2/equipment/brand/?website=*", {
    count: 0,
    next: null,
    previous: null,
    results: []
  }).as("findBrandsByWebsite");

But then I see that the stub is not been used.

What am I missing?

Thanks!

enter image description here

2 Answers

I'm still not sure why that route wouldn't catch, but using it as a regular expression instead fixed the problem:

  cy.route("GET", /\/api\/v2\/equipment\/brand\/\?website=.*/, {
    count: 0,
    next: null,
    previous: null,
    results: []
  }).as("findBrandsByWebsite");

With cy.intercept there's a pattern that allows the query part to be defined separately With RouteMatcher

cy.intercept({
  url: "**/api/v2/equipment/brand",
  query: { website: '*' },
})
Related