Reactjs 使用react测试库在react窗口列表中进行测试滚动

Reactjs 使用react测试库在react窗口列表中进行测试滚动,reactjs,react-testing-library,react-window,Reactjs,React Testing Library,React Window,我在这里遇到了一个测试,我想验证在通过react window导入的列表组件滚动之后,是否呈现了不同的项目。列表位于一个表组件中,该组件在React上下文中保存滚动位置,这就是为什么我需要测试整个表组件 不幸的是,滚动事件似乎没有效果,列表仍然显示相同的项目 该测试如下所示: render( <SomeProvider> <Table /> </SomeProvider> ) describe('Table', () => { it

我在这里遇到了一个测试,我想验证在通过react window导入的列表组件滚动之后,是否呈现了不同的项目。列表位于一个表组件中,该组件在React上下文中保存滚动位置,这就是为什么我需要测试整个表组件

不幸的是,滚动事件似乎没有效果,列表仍然显示相同的项目

该测试如下所示:

render(
  <SomeProvider>
    <Table />
  </SomeProvider>
)

describe('Table', () => {
  it('scrolls and renders different items', () => {
    const table = screen.getByTestId('table')

    expect(table.textContent?.includes('item_A')).toBeTruthy() // --> true
    expect(table.textContent?.includes('item_Z')).toBeFalsy() // --> true

    // getting the list which is a child component of table
    const list = table.children[0]

    fireEvent.scroll(list, {target: {scrollY: 100}})

    expect(table.textContent?.includes('item_A')).toBeFalsy() // --> false
    expect(table.textContent?.includes('item_Z')).toBeTruthy() // --> false
  })
})
渲染(
)
描述('表',()=>{
它('滚动并呈现不同的项目',()=>{
const table=screen.getByTestId('table'))
expect(table.textContent?.includes('item_A')).toBeTruthy()//-->true
expect(table.textContent?.includes('item_Z')).toBeFalsy()//-->true
//获取作为表的子组件的列表
常量列表=表。子项[0]
滚动(列表,{target:{scrollY:100})
expect(table.textContent?.includes('item_A')).toBeFalsy()//-->false
expect(table.textContent?.includes('item_Z')).toBeTruthy()//-->false
})
})
任何帮助都将不胜感激