component-driven / cypress-axe

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

how to config checkA11y for all tests #156

Open kitsguru opened 1 year ago

kitsguru commented 1 year ago

I have a series of specs for different sections and modules of my app. I would like to configure checkA11y in one location for all specs.

This works within each test

cy.checkA11y(null, {
    rules: {
        'color-contrast': { enabled: false },
        'frame-title': { enabled: false },
        },
});

I tried to set the configuration in support/index.js but I get an error

beforeEach(function () {
    // runs before each test in the block
    cy.visit('/')
    cy.injectAxe()
    cy.configureAxe({
        rules: {
            'color-contrast': { enabled: false },
            'frame-title': { enabled: false },
        },
    })
});

I am unsure where to set this up correctly.

aamir-yaseen-baba commented 1 year ago

In the support, folder create a file e.g say axe-cofig.js and in that file create an object like this

export const defaultAxeConfiguration = {
    rules:[ {
       id: 'color-contrast', enabled: true,
    }],
    disableOtherRules: true,
};

and write your beforeEach like this beforeEach(()=>{ cy.visit('/') cy.injectAxe() cy.configureAxe(defaultAxeConfiguration) })