Yogendra
Yogendra

Reputation: 107

How to select an element (Text, View) in react-native with jest+enzyme (mostly when Text/View are nested deep-down in the component)?

I know of something called find in enzyme, but I'd like to know how to select a react-native element by some attribute

Upvotes: 1

Views: 752

Answers (1)

Yogendra
Yogendra

Reputation: 107

You can select it by any attribute like id, e.g,

for selecting the following Text in testing.js

<Text id="myid">hello </Text>

you can do the following

it('selects Text with id attr', () => {
  let wrapper = shallow(<Testing />);
  let text = wrapper.findWhere(node => node.name() === 'Text' && node.prop('id') === 'myid');
  console.log(text.debug());
})

Upvotes: 0

Related Questions