I am trying to assert that a route has not been called in Cypress. I thoroughly looked through the documentation and have found nothing.
I am trying to do something like this:
cy.get('@myRouteAlias').should('have.not.been.called');
I am currently working around this by asserting that the successful request toast message is not being displayed but it is a flimsy solution.
Any ideas?
It is very difficult to test a situation where an action has not occured. With this type of assertion, you can really only say:
"The XHR request was not made within the 400ms
that Cypress looked for this XHR request to have been made (or whatever you set your timeout to be)"
This doesn't really confirm that the XHR request was never called.
That being said, Cypress offers a way to retrieve all XHR requests made using the undocumented cy.state('requests')
. You could check the length of that, filter them by alias, etc to probably determine what you want.