import React from "react"; import { Text } from "react-native"; import "@quilted/react-testing/matchers"; import { render, Root } from "@quilted/react-testing"; import FlashList from "../../FlashList"; import { FlashListProps, ListRenderItem } from "../../FlashListProps"; jest.mock("../../FlashList", () => { const ActualFlashList = jest.requireActual("../../FlashList").default; class MockFlashList extends ActualFlashList { componentDidMount() { super.componentDidMount(); this.rlvRef?._scrollComponent?._scrollViewRef?.props.onLayout({ nativeEvent: { layout: { height: 900, width: 400 } }, }); } } return MockFlashList; }); export type MockFlashListProps = Omit< FlashListProps, "estimatedItemSize" | "data" | "renderItem" > & { estimatedItemSize?: number; data?: string[]; renderItem?: ListRenderItem; disableDefaultEstimatedItemSize?: boolean; }; /** * Helper to mount FlashList for testing. */ export const mountFlashList = ( props?: MockFlashListProps, ref?: React.RefObject> ) => { const flashList = render(renderFlashList(props, ref)) as Omit< Root>, "instance" > & { instance: FlashList; }; return flashList; }; export function renderFlashList( props?: MockFlashListProps, ref?: React.RefObject> ) { return ( {item})} estimatedItemSize={ props?.estimatedItemSize ?? (props?.disableDefaultEstimatedItemSize ? undefined : 200) } data={props?.data || ["One", "Two", "Three", "Four"]} /> ); }