I'm tying to set up some basic testing in cypress, stubbing some basic http calls using cy.server() cy.route() and cy.wait(). In my app, I need to assert on the number of times that the route has been stubbed. For instance, when I submit a form it send a request to localhost:3001, if I submit the form again it will submit again. I want to assert on the number of submissions. Something like expect(xhr).to.have.lenght(2), or something similar, but I can't figure out how.
This is my simple test so far
it("Checking number of requests", () => {
cy.server();
cy.route({
method: "POST",
url: "**/signupNewUser*",
response: {
kind: "identitytoolkit#SignupNewUserResponse",
idToken: "sarasa",
email: "[email protected]",
refreshToken: "sarasa2",
expiresIn: "3600",
localId: "sarasa3",
customTestingProperty: "custom"
}
}).as("postAPI");
cy.fillForm(password);
cy.contains("Submit").click();
cy.contains("Submit").click();
// Here I would like to assert that "**/signupNewUser*" has been requested 2 times.
// I don't want to test for how many times has the button been clicked or the form been submitted.
});