diff --git a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js index b02757cadf9..6fe771ea183 100644 --- a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js +++ b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js @@ -1836,56 +1836,49 @@ it('retains initial render region when an item is appended', async () => { expect(component).toMatchSnapshot(); }); -// TODO: Revisit this test case after upgrading to React 19. -skipTestSilenceLinter( - 'retains batch render region when an item is appended', - async () => { - const items = generateItems(10); - const ITEM_HEIGHT = 10; +it('retains batch render region when an item is appended', async () => { + const items = generateItems(10); + const ITEM_HEIGHT = 10; - let component; - await act(() => { - component = create( - , - ); - }); + let component; + await act(() => { + component = create( + , + ); + }); - await act(() => { - simulateLayout(component, { - viewport: {width: 10, height: 50}, - content: {width: 10, height: 100}, - }); - performAllBatches(); + await act(() => { + simulateLayout(component, { + viewport: {width: 10, height: 50}, + content: {width: 10, height: 100}, }); + }); - await act(async () => { - await jest.runAllTimersAsync(); - }); + await advanceUntilLastCellIndexRendered(component, items.length - 1); - await act(() => { - component.update( - , - ); - }); + await act(() => { + component.update( + , + ); + }); - // Adding an item to the list after batch render should keep the existing - // rendered items rendered. We batch render 10 items, then add an 11th. Expect - // the first ten items to be present, with a spacer for the 11th until the - // next batch render. - expect(component).toMatchSnapshot(); - }, -); + // Adding an item to the list after batch render should keep the existing + // rendered items rendered. We batch render 10 items, then add an 11th. Expect + // the first ten items to be present, with a spacer for the 11th until the + // next batch render. + expect(component).toMatchSnapshot(); +}); it('constrains batch render region when an item is removed', async () => { const items = generateItems(10); @@ -2639,13 +2632,30 @@ async function advanceUntilRenderAreaChanged(component) { } await act(() => { - jest.advanceTimersToNextTimer(1); + performNextBatch(); }); } throw new Error(`Render area did not change`); } +async function advanceUntilLastCellIndexRendered(component, targetLastIndex) { + const instance = component.getInstance(); + const MAX_TIMER_STEPS = 20; + + for (let step = 0; step < MAX_TIMER_STEPS; step++) { + if (instance.state.cellsAroundViewport.last === targetLastIndex) { + return; + } + + await act(() => { + performNextBatch(); + }); + } + + throw new Error(`Target last index ${targetLastIndex} not rendered`); +} + function performAllBatches() { jest.runAllTimers(); }