Reputation: 31
I currently have an issue where our FE app under test is sending multiple tracking requests, does anyone have any suggestions on how to assert that once the xhr Route has been configured in Cypress that I can assert that it's only been called once?
Upvotes: 3
Views: 1291
Reputation: 17889
let count = 0;
for (let i in [1,2,3,4,5]) {
cy.route({url:'your_url', response:[], delay:1000}).as(`req${i}`);
cy.get('button').click();
cy.wait(`@req${i}`).then(()=> {
count++;
});
cy.wait(5000).then(()=> {
expect(count).to.equal(1);
});
}
Upvotes: 3