Open softlore opened 2 weeks ago
Hi team,
Following is the libraries & versions I use in my project
Below is the outline of components & test file I have used in my project
const CustomList = () => { const [val, setVal] = useState(null); const { data, loading } = uiController() const handleRedirect = () => { } if(loading){ return <Text testID='loaderPage'>Loading...</Text> } return <> <RedirectComponent val={val} onRequestComplete={handleRedirect}/> <FlatList data renderItem={({ item }) => { return <View> <Pressable testID='listItem' onPress={() => setVal(item.id)}/> </View> }} /> </> }
describe('CustomList', () => { it('should render loader page', () => { jest.mock('~/ui-controller', () => ({ data: [], loading: true })) const { getByTestId } = render(<MockedProvider mocks={[...]}> <CustomList/> </MockedProvider>) expect(getByTestId('loaderPage')).toBeDefined() }) it('should handle redirect', () => { jest.mock('~/ui-controller', () => ({ data: [{ id: 1 }], loading: false })) const { getByTestId, queryAllByTestId } = render(<MockedProvider mocks={[...]}> <CustomList/> </MockedProvider>) const listItems = queryAllByTestId('listItem') fireEvent.press(listItems[0]) expect(queryByText('1')).toBeDefined() fireEvent.press(getByTestId('redirect-btn')) }) })
const RedirectMock = ({ val, onRequestComplete }) => { return <View> <Text>{val}</Text> <Pressable testID='redirect-btn' onPress={onRequestComplete}/> </View> }
Initially I was getting the following error
fireEvent.press(getByTestId('redirect-btn')) --> Found mulitple element with testID: redirect-btn
But getByText('1') gives only one item.
So I added a cleanup & resetModules in the afterEach method:
afterEach(() => { cleanup(); jest.resetModules(); })
Now, I am getting the following error:
TypeError: Cannot read properties of null (reading 'useMemo')
I am unable to share the full stacktrace, but error comes from the following file:
/react-native/Libraries/Lists/VirtualizedListContext.js
at line:
export function VirtualizedListContextProvider({ children, value, }: { children: React.Node, value: Context }): React.Node { const context = useMemo(
Hi team,
Following is the libraries & versions I use in my project
Below is the outline of components & test file I have used in my project
Component
Test File
redirect component mock
Errors
Initially I was getting the following error
But getByText('1') gives only one item.
So I added a cleanup & resetModules in the afterEach method:
Now, I am getting the following error:
I am unable to share the full stacktrace, but error comes from the following file:
/react-native/Libraries/Lists/VirtualizedListContext.js
at line: