cypress-axe
cypress-axe copied to clipboard
how to config checkA11y for all tests
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.
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) })