T
TanStack14mo ago
afraid-scarlet

Testing a table that uses virtual with React Testing Library

I have a component that is using react-virtual and it works as expected in the UI but when testing I see that the getVirtualItems returns an empty array. Can someone please provide an example for testing using Jest and/or RTL? I can't share code because it is confidential but I think my description is as clear as possible. Thanks!
2 Replies
fascinating-indigo
fascinating-indigo14mo ago
Hi, you need to moc the scroll element to return some height, https://github.com/TanStack/virtual/issues/641#issuecomment-1875566247
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...
afraid-scarlet
afraid-scarletOP14mo ago
Thanks!

Did you find this page helpful?