Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useVirtualizer not working in Vue Test Utils #709

Open
2 tasks done
Fedezable opened this issue Apr 17, 2024 · 2 comments
Open
2 tasks done

useVirtualizer not working in Vue Test Utils #709

Fedezable opened this issue Apr 17, 2024 · 2 comments

Comments

@Fedezable
Copy link

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.
@Fedezable Fedezable changed the title useVirtualizer not working wtth Vue Test Utils useVirtualizer not working in Vue Test Utils Apr 17, 2024
@Zertz
Copy link

Zertz commented May 14, 2024

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.

@piecyk
Copy link
Collaborator

piecyk commented May 14, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants