Skip to content

Commit 160f0cd

Browse files
chicioCopilot
andcommitted
refactor(test): re-enable test for retain batch region weh item append (react 19 differen)
Co-authored-by: Copilot <copilot@github.com>
1 parent 44a4b1b commit 160f0cd

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,8 +1836,7 @@ it('retains initial render region when an item is appended', async () => {
18361836
expect(component).toMatchSnapshot();
18371837
});
18381838

1839-
// TODO: Revisit this test case after upgrading to React 19.
1840-
skipTestSilenceLinter(
1839+
it(
18411840
'retains batch render region when an item is appended',
18421841
async () => {
18431842
const items = generateItems(10);
@@ -1860,12 +1859,9 @@ skipTestSilenceLinter(
18601859
viewport: {width: 10, height: 50},
18611860
content: {width: 10, height: 100},
18621861
});
1863-
performAllBatches();
18641862
});
18651863

1866-
await act(async () => {
1867-
await jest.runAllTimersAsync();
1868-
});
1864+
await advanceUntilLastCellIndexRendered(component, items.length - 1);
18691865

18701866
await act(() => {
18711867
component.update(
@@ -2639,13 +2635,30 @@ async function advanceUntilRenderAreaChanged(component) {
26392635
}
26402636

26412637
await act(() => {
2642-
jest.advanceTimersToNextTimer(1);
2638+
performNextBatch();
26432639
});
26442640
}
26452641

26462642
throw new Error(`Render area did not change`);
26472643
}
26482644

2645+
async function advanceUntilLastCellIndexRendered(component, targetLastIndex) {
2646+
const instance = component.getInstance();
2647+
const MAX_TIMER_STEPS = 20;
2648+
2649+
for (let step = 0; step < MAX_TIMER_STEPS; step++) {
2650+
if (instance.state.cellsAroundViewport.last === targetLastIndex) {
2651+
return;
2652+
}
2653+
2654+
await act(() => {
2655+
performNextBatch();
2656+
});
2657+
}
2658+
2659+
throw new Error(`Target last index ${targetLastIndex} not rendered`);
2660+
}
2661+
26492662
function performAllBatches() {
26502663
jest.runAllTimers();
26512664
}

0 commit comments

Comments
 (0)