TanStack / TanStack/virtual

useVirtualizer not working in Vue Test Utils

Open
#709 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.1k
Forks
466
Avg merge
2d 31m
Merged PRs (30d)
13

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Vue example component based on RowVirtualizerFixed.vue and the RowVirtualizerFixed.test.ts reproduction described in the issue. Run the Vitest test and inspect wrapper.html alongside the virtualizer's rendered output. Done means the test environment renders virtualized rows in the wrapper HTML, matching the app's behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.