Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1612,11 +1612,10 @@ it('adjusts render area with non-zero initialScrollIndex', async () => {
content: {width: 10, height: 200},
});
simulateScroll(component, {x: 0, y: 10}); // simulate scroll offset for initialScrollIndex

// TODO: Rewrite test to tolerate subtle timing changes.
jest.advanceTimersToNextTimer(3);
});

await advanceUntilRenderAreaChanged(component);

// We should expand the render area after receiving a message indicating we
// arrived at initialScrollIndex.
expect(component).toMatchSnapshot();
Expand Down Expand Up @@ -2624,6 +2623,29 @@ function simulateScroll(component, position) {
});
}

async function advanceUntilRenderAreaChanged(component) {
const instance = component.getInstance();
const initialRenderArea = instance.state.cellsAroundViewport;
const MAX_TIMER_STEPS = 20;

for (let step = 0; step < MAX_TIMER_STEPS; step++) {
const currentRenderArea = instance.state.cellsAroundViewport;
const renderAreaChanged =
currentRenderArea.first !== initialRenderArea.first ||
currentRenderArea.last !== initialRenderArea.last;

if (renderAreaChanged) {
return;
}

await act(() => {
jest.advanceTimersToNextTimer(1);
});
}

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

function performAllBatches() {
jest.runAllTimers();
}
Expand Down
Loading