When we have the route:
cy.intercept('PUT', '**/shoes/*', body).as('updateShoes');
The following solution worked for me:
cy.get('@updateShoes').then((interception) => {
assert.isNull(interception)
});
Cypress says:
expected null to equal null
When the '@updateShoes' route was called than (interception) is a Object:
{id: "interceptedRequest551", routeId: "1623772693273-2831", request: {…}, state: "Complete", requestWaited: false, …}
id: "interceptedRequest551"
log: {get: ƒ, unset: ƒ, invoke: ƒ, toJSON: ƒ, set: ƒ, …}
request: {headers: {…}, url: "http://localhost:8080/api/shoes/38de4e08", method: "PUT", httpVersion: "1.1", body: {…}}
requestWaited: false
response: {headers: {…}, body: {…}, url: "http://localhost:8080/api/shoes/38de4e08", method: null, httpVersion: null, …}
responseWaited: false
routeId: "1623772693273-2831"
state: "Complete"
subscriptions: []
...}
And Cypress throws an error:
AssertionError
expected { Object (id, routeId, ...) } to equal null
should("not.have.been.called")
in Cypress 13.6 (and possibly earlier, I haven't checked). See github.com/cypress-io/cypress/discussions/… and https://mcmap.net/q/367605/-is-there-a-way-to-assert-that-a-route-has-not-been-called-in-cypress-duplicate below. Note that it's"not.have.been.called"
, not (as in the question above)"have.not.been.called"
. You also need to use a spy. – Loathing