Closed
Description
Versions
react: 16.9.0
react-native: 0.61.5
react-native-testing-library: 1.13.0
react-test-renderer: 16.9.0
Description
When attempting to find multiple items with the same testID property (FlatList render item), I am unable to fetch any test components using getAllByTestId.
getByTestId does return the first item with that test ID in the virtual DOM.
I am able to get all of the test items by using the test renderer directly and doing a findAllByProp query from there.
Reproducible Demo
import { render, RenderAPI } from 'react-native-testing-library';
import { FlatList, Text } from 'react-native';
import { create } from 'react-test-renderer';
class ListItem extends React.Component<{ testID: string }> {
render() {
return <Text>foo</Text>;
}
}
it('should have two items', () => {
const renderer = render((
<FlatList data={[{}, {}]} renderItem={() => <ListItem testID="listItem" />} />
));
expect(renderer.getAllByTestId('listItem')).toHaveLength(2);
});
it('should have two items', () => {
const renderer = create((
<FlatList data={[{}, {}]} renderItem={() => <ListItem testID="listItem" />} />
));
expect(renderer.root.findAllByProps({ testID: 'listItem' })).toHaveLength(2);
});