[Solved] No rows rendered via testing-library/react
I'm trying to write tests for my component that renders a table via
useMantineReactTable
(wrapper around react table that renders Mantine components). The component itself works, the data from the query gets piped into the component and everything works fine on the actual page but when I render in my tests I don't see any rows getting populated in the table.
- I've verified that the MSW handler is being called.
- I've verified the data is being passed to useMantineReactTable
.
- I've verified a row shows up when the same data is returned from my react-query hook in the actual page.
- I'm using waitFor
on text that updates when the data is returned.
But my await waitFor(() => screen.findByText(expectedCellText));
always fails. Using screen.debug
I've been able to pull up the tbody:
It's always empty.
I'm not sure what I may be doing wrong, or if there is something I can pass to waitFor
. I've tried upping the timeout on waitFor
to 2 seconds but still nothing.
If it matters, the rows are virtualized.3 Replies
ratty-blushOP•2y ago
Here's a sample of a passing test (the elements "around" the table are all updating):
That
screen.debug
is still printing an empty tbody -- the data is updating the bottom toolbar (the Load More button and the showing text) which is configured through useMantineReactTable
call so it's being updated as the query is updated/actions are taken but still no rows render.ambitious-aqua•2y ago
you're probably running into this https://github.com/TanStack/virtual/issues/641
GitHub
No rows returned by useVirtualizer in unit tests · Issue #641 · Tan...
Describe the bug In browser table rows are rendered as expected. In unit tests useVirtualizer returns an empty array from rowVirtualizer.getVirtualItems(). The bug is introduce with changes introdu...
ratty-blushOP•2y ago
Huzzah, I missed that looking through open issues because it's on TanStack/virtual -- which I did not realize was in use here. Thanks so much!