Assert if Cypress route only called once

Viewed 1179

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?

1 Answers

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);
  });
}

Related