component-driven / cypress-axe

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

Exclude color-contrast for disabled fields using disabled attribute. #168

Open sandeep-chennupati opened 11 months ago

sandeep-chennupati commented 11 months ago

Hi, I am trying to disable/exclude color-contrast only on disabled fields in cypress-axe. Is it possible?

const off = [
    'html-has-lang',
    'landmark-one-main',
    'page-has-heading-one',
    'region',
];

// config: https://github.com/component-driven/cypress-axe#cyconfigureaxe
// context, options: https://github.com/component-driven/cypress-axe#cychecka11y
export default (
    node = null,
    config = {rules: []},
    {context = null, options = null} = {
        context: null,
        options: null,
    },
    delay = 0
) => {
    init({
        ...config,
        rules: off
            .map(id => ({
                id,
                enabled: false,
            }))
            .concat(config.rules),
    });

    // add a .wait to make sure a render cycle is run before checkA11y so that
    // the styles for the element(s) can be applied before a11y tests are executed
    return mount(node).wait(delay).checkA11y(context, options, terminalLog);
};