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.
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
CommandBar (v8): convert tests to use testing-library #22247
CommandBar (v8): convert tests to use testing-library #22247
Changes from 1 commit
5d0053b
dcd935f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another case that testing-library deems as "inaccessible" for seemingly no reason 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was bothering me enough that I started looking at the testing-library code, and I figured it out...it's the measurement/overflow logic in some of our components, including CommandBar and Breadcrumb. I don't know the details of how measurement works, but the general idea is that it initially renders stuff hidden and/or off-screen to get the size, then re-renders with appropriate size and overflow items.
getByRole
is running against that initial measurement render, where the elements are in fact hidden.How I figured this out was a little over-complicated, and in retrospect I probably should have tried running the test and stepping through the code first. 😆
What I actually did: I started by looking in
@testing-library/dom
's code for the implementation of therole
query and searching forhidden
. That led to theisInaccessible
implementation. I wasn't sure exactly what would cause issues there, so I made a codepen that renders a basic Breadcrumb (since it has the same problem and is a little simpler) and runsisInaccessible
against the list items after render.Turns out
getComputedStyle(element).visibility
was returning'hidden'
. This seemed weird (since I could see the breadcrumb on the page) but then I remembered that Breadcrumb and CommandBar have measurement with initial hidden rendering. So I tried runningisInaccessible
on the items again after a 500ms timeout and it returns false (is accessible) as expected.https://codepen.io/ecraig12345/pen/RwxZwdN?editors=0011
Anyway...the possible solutions for the tests are:
{ hidden: true }
and add comments that it's due to the measurement logicgetByRole
on itemsDefinitely any tests that involve overflow should use fake timers, but in other cases it's up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow - the initial hidden rendering of some of our components is quite the gotcha in this case😆. Thanks a lot for looking into this!