feat: Add strictVisibility check option to ByRole queries #1331
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.
What:
Added an option called
strictVisibilityCheck
that defaults totrue
(for now). Iftrue
it will use the existing code path that does agetComputedStyle
on each node to check visibility during queriesByRole
. If set tofalse
, the visibility check settles for a more lose algorithm that doesn't rungetComputedStyle
.Why:
This is being added as a means of improving performance of tests using queries like
getAllByRole
on larger sets of DOM elements, as can be found in many real-world applications. Anecdotally, using this setting fixed one test I had locally from8000ms
to500ms
total. (still not great, but miles better).How:
Added an option to the type definition, threaded it through the existing logic, and added a "loose" check for inaccessibility. I added a test with a few checks to make sure the default is still working as expected, and the new setting still works in a similar manner.
It's worth noting that I tried to add a test that checked "indirect" visibility alterations through CSS classes, however, I was unable to get the test harness to recognize the CSS class and trigger layout (I was probably doing something wrong there, happy to follow up).
Checklist:
docs site