Skip to content

How to pass exclude option? #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stereobooster opened this issue Jun 6, 2021 · 7 comments
Open

How to pass exclude option? #8

stereobooster opened this issue Jun 6, 2021 · 7 comments

Comments

@stereobooster
Copy link

Hi,
thanks for maintaining the fork.

Maybe you know how to pass exclude option?

@mwmcode
Copy link
Owner

mwmcode commented Jun 6, 2021

Hi @stereobooster ,

I tried to implement the changes that were planned for the next release of cypress-axe so this option has been replaced by shouldFailFn callback.

You can exclude a whole category/impact, for example exclude critical

cy.checkA11y({
  shouldFailFn: violations => violations.filter(v => v.impact !== 'critical')
});

or a certain violation like color-contrast:

cy.checkA11y({
  shouldFailFn: violations =>
    violations.filter(v.id !== 'color-contrast')
});

If you have certain violations/impacts that you want to exclude app wide, consider creating a custom command https://github.com/mcha-dev/cypress-axe-core#customised

@stereobooster
Copy link
Author

I meant an option to exclude dom node, something like this:

context: {
  include: window
  exclude: ['[data-skip]']
}

@mwmcode
Copy link
Owner

mwmcode commented Jun 6, 2021

Interesting! this has been abstracted in this implementation. Try this temporary workaround.

<img class="notme" src="" /> 
cy.wrap({ exclude: ['.notme']}).checkA11y();

@stereobooster
Copy link
Author

Thanks.

My use case is: I have some components which use brand colors and lack contrast, so I want to ignore them until we get new color scheme from designers.

mwmcode pushed a commit that referenced this issue Jun 6, 2021
option to pass axeContext to better address scenarios as in issue #8

re #8
@mwmcode
Copy link
Owner

mwmcode commented Jun 6, 2021

That's a valid scenario. Glad I could help.

@stereobooster
Copy link
Author

WDYT about following API:

cy.get('bla').checkA11y({ exclude: ['.notme']});

?

@mwmcode
Copy link
Owner

mwmcode commented Jun 8, 2021

It might not be as straightforward as that. I don't want to spread the context props over the current config options.

Will look into it later, for now I will update the readme to include the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants