component-driven / cypress-axe

Test accessibility with axe-core in Cypress
MIT License
618 stars 86 forks source link

Add severity levels to fail on #137

Open roc opened 2 years ago

roc commented 2 years ago

I found that the includedImpacts option was very helpful, but got me into a weird state in which I could have failures but not have the assertions logged out.

Here I've put together a rough and ready implementation of failure levels, meaning you can choose which levels of error you think are important enough to fail on per test. The way I've been using it is:

    it('Fails only if the accessibility error is of serious or critical level', () => {
      const failOn = ['serious', 'critical'];
      cy.visit('/home');
      cy.injectAxe();
      cy.checkA11y(null, null, a11yLogFunction, failOn);
    });