Reputation: 154
How to test FlatList using Jest and Enzyme? I cant figure out how to check if it has got keyExtractor or not.
it('flatlist should have keyExtractor', () => {
wrapper
.find('FlatList')
.props()
.keyExtractor();
});
});
Upvotes: 1
Views: 4480
Reputation: 48
you need to pass the item in .keyExtractor()
to test the return. For example:
If you have:
<FlatList
data={data}
renderItem={this.renderItem}
keyExtractor={item => item.id.toString()}
/>
Now the test:
it('should flatlist return keyExtractor correctly', () => {
const key = wrapper
.find('FlatList')
.props()
.keyExtractor({id: 3});
expect(key).toEqual('3')
});
Upvotes: 2