Add shouldIgnoreViolation
optional prop to Scenario for a11y tests
#12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
We have recently found an accessibility test that was failing dues to axe-core not allowing a very specific combination of elements, specifically a button with combobox role linked with a label using its
for
attribute.While the specification says this is a valid combination, there's a specific screen reader which does not play well with it, and that's why axe-core reports a violation.
We have tested the combination with other screen readers (VoiceOver and orca), and the elements get announced as expected, so we want to be able to ignore this violation.
Changes
This PR introduces a new
shouldIgnoreViolation
callback that can be provided as part of every scenario passed tocheckAccessibility
.This callback is invoked with every violation reported by axe-core, allowing downstream code to determine which violations are relevant and which are not.
I decided to use this approach instead of just providing the ids of violations to ignore, because then we could end up ignoring actual violations by mistake.
With this, downstream code has all the information about the violation in order to decide whether it has to be ignored or not.
How to use
As a POC, I have used this PR in client in the test where this was first spotted, so it will look more or less like this: