Cypress: verify click on downloadlink

What I needed was a way to check if a click on a downloadlink actually triggered a download.

Solution:

cy.intercept('GET', 'someurl/Download/*').as('download');
cy.get('[data-cy="downloadlink"]').click();
cy.wait('@download');
cy.get("@download").then(xhr => {
   expect(xhr.response.statusCode).to.equal(200);
});

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.