Skip to content
Source
Sign inSign up
TanStack/virtual

test: add solid-virtual tests #1286

Opengameroman(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1286/headopened

Showing 2 changed files with 95 additions and 0 deletions.

x
0 of 2 viewed, 2 left
51 additions and 0 deletionspackages/solid-virtual/tests/filter-items.test.tsAdded
View file
@@ -0,0 +1,51 @@
+import { expect, test } from 'vitest'
+import { createRoot, createSignal } from 'solid-js'
+​
+import { createVirtualizer } from '../src/index'
+​
+test('virtual items correctly index into filtered data after reactive shrink', () => {
+ createRoot((dispose) => {
+ const all = ['apple', 'banana', 'cherry', 'date', 'fig', 'grape']
+ const [query, setQuery] = createSignal('')
+​
+ const filtered = () => {
+ const q = query()
+ if (!q) return all
+ return all.filter(s => s.includes(q))
+ }
+​
+ const virtualizer = createVirtualizer<HTMLDivElement, HTMLDivElement>({
+ get count() {
+ return filtered().length
+ },
+ getScrollElement: () => null,
+ estimateSize: () => 60,
+ initialRect: { width: 800, height: 600 },
+ })
+​
+ expect(virtualizer.getVirtualItems().length).toBe(6)
+ expect(virtualizer.getVirtualItems().map(v => filtered()[v.index]))
+ .toEqual(['apple', 'banana', 'cherry', 'date', 'fig', 'grape'])
+​
+ setQuery('e')