Testing tablesJanuary 30, 2020 at 6:56pm
Hi All I'm trying to assert how many rows are in a table It should be simple enough but I can't find a way to to queryXXX('tr') or equivalent It goes a bit againts the philosophy of testing library to test what the user can see, but counting rows is something users can do ^^ Any ideas ?
January 30, 2020 at 7:06pm
Hi! You can use
ByRolequery for that (https://testing-library.com/docs/dom-testing-library/api-queries#byrole). In the doc you can find a link to aria-query to see corresponding roles for different elements. You’ll find there that “row” work as role for a “tr” element.
February 2, 2020 at 3:24pm
I did however spot one of our dependencies (react-table) has a markup like this
<divclass="rt-tbody"style="min-width: 400px;"><divclass="rt-tr-group"role="rowgroup"><divclass="rt-tr -odd"role="row"><divclass="rt-td"role="gridcell"style="flex: 100 0 auto; width: 100px;">
Do you have a good strategy for this ?
February 3, 2020 at 4:12am