TanStack / virtual

🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte

Home Page:https://tanstack.com/virtual

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useVirtualizer not working in Vue Test Utils

Fedezable opened this issue · comments

Describe the bug

The virtualizer doesn't seem to work when used in Vue Test Utils.

Your minimal, reproducible example

Steps to reproduce

  1. Create a new vite app with vue + ts template
    npm create vite@latest

  2. Install vitest and vue test utils
    npm i vitest
    npm i @vue/test-utils

  3. Create a new component based on any vue tanstack virtual example, I tried with: -> RowVirtualizerFixed.vue in fixed example

  4. Create a new basic test file RowVirtualizerFixed.test.ts and log the wrapper's html:

import { mount } from '@vue/test-utils'
import { describe, it } from 'vitest'
import VirtualRowsExample from './VirtualRowsExample.vue'

describe('VirtualRowsExample', () => {
  it('should render virtualized rows', () => {
    const wrapper = mount(VirtualRowsExample)
    console.log(wrapper.html())
  })
})

  1. Run the tests
  2. As you will see the wrapper won't print any html where the rows should be visible

Looks like rowVirtualizer.value.getVirtualItems is not returning any row

<div class="List" style="height: 200px; width: 400px; overflow: auto;">
  <div style="height: 350000px; width: 100%; position: relative;"></div>
</div>

The component looks fine when used in the app

Expected behavior

Some Rows should be printed in wrapper's html

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Windows

tanstack-virtual version

3.0.4

TypeScript version

4.9.3

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

For us, the last working version is 3.0.0-beta.62. Every version from 3.0.0-beta.63 to 3.5.0 fails our tests.

This is expected as in jsdom environment getBoundingClientRect will return height 0 for scroller element. There few options we can tackle this, one is to mock getBoundingClientRect using vi.fn have a look at #641 (comment)