diff --git a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js index 2a5214438bc16d..33ea0d60c2f0d9 100644 --- a/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js +++ b/packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js @@ -18,49 +18,58 @@ import {act, create} from 'react-test-renderer'; jest.useFakeTimers(); describe('VirtualizedList', () => { - it('renders simple list', () => { - const component = create( - } - getItem={(data, index) => data[index]} - getItemCount={data => data.length} - />, - ); + it('renders simple list', async () => { + let component; + await act(() => { + component = create( + } + getItem={(data, index) => data[index]} + getItemCount={data => data.length} + />, + ); + }); expect(component).toMatchSnapshot(); }); - it('renders simple list using ListItemComponent', () => { + it('renders simple list using ListItemComponent', async () => { function ListItemComponent({item}) { return ; } - const component = create( - data[index]} - getItemCount={data => data.length} - />, - ); + let component; + await act(() => { + component = create( + data[index]} + getItemCount={data => data.length} + />, + ); + }); expect(component).toMatchSnapshot(); }); - it('warns if both renderItem or ListItemComponent are specified. Uses ListItemComponent', () => { + it('warns if both renderItem or ListItemComponent are specified. Uses ListItemComponent', async () => { jest.spyOn(console, 'warn').mockImplementationOnce(() => {}); function ListItemComponent({item}) { return ; } - const component = create( - ( - - )} - getItem={(data, index) => data[index]} - getItemCount={data => data.length} - />, - ); + let component; + await act(() => { + component = create( + ( + + )} + getItem={(data, index) => data[index]} + getItemCount={data => data.length} + />, + ); + }); expect(console.warn).toBeCalledWith( 'VirtualizedList: Both ListItemComponent and renderItem props are present. ListItemComponent will take precedence over renderItem.', @@ -97,29 +106,35 @@ describe('VirtualizedList', () => { console.error.mockRestore(); }); - it('renders empty list', () => { - const component = create( - } - getItem={(data, index) => data[index]} - getItemCount={data => data.length} - />, - ); + it('renders empty list', async () => { + let component; + await act(() => { + component = create( + } + getItem={(data, index) => data[index]} + getItemCount={data => data.length} + />, + ); + }); expect(component).toMatchSnapshot(); }); - it('renders empty list after batch', () => { - const component = create( - } - getItem={(data, index) => data[index]} - getItemCount={data => data.length} - />, - ); + it('renders empty list after batch', async () => { + let component; + await act(() => { + component = create( + } + getItem={(data, index) => data[index]} + getItemCount={data => data.length} + />, + ); + }); - act(() => { + await act(() => { simulateLayout(component, { viewport: {width: 10, height: 50}, content: {width: 10, height: 200}, @@ -131,148 +146,177 @@ describe('VirtualizedList', () => { expect(component).toMatchSnapshot(); }); - it('renders null list', () => { - const component = create( - } - getItem={(data, index) => data[index]} - getItemCount={data => 0} - />, - ); + it('renders null list', async () => { + let component; + await act(() => { + component = create( + } + getItem={(data, index) => data[index]} + getItemCount={data => 0} + />, + ); + }); expect(component).toMatchSnapshot(); }); - it('scrollToEnd works with null list', () => { + it('scrollToEnd works with null list', async () => { const listRef = React.createRef(null); - create( - } - getItem={(data, index) => data[index]} - getItemCount={data => 0} - ref={listRef} - />, - ); + await act(() => { + create( + } + getItem={(data, index) => data[index]} + getItemCount={data => 0} + ref={listRef} + />, + ); + }); listRef.current.scrollToEnd(); }); - it('renders empty list with empty component', () => { - const component = create( - } - ListFooterComponent={() =>