React Enzyme find second (or nth) node React Enzyme find second (or nth) node reactjs reactjs

React Enzyme find second (or nth) node


What you want is the .at(index) method: .at(index) .

So, for your example:

expect(component.find('MyInnerComponent').at(1)).toHaveProp('title', 'Good-bye');


If you are to test certain things on each one also consider iterating through the matched set:

component.find('MyInnerComponent').forEach( (node) => {    expect(node.prop('title')).toEqual('Good-bye')})


 const component = wrapper.find('MyInnerComponent').at(1);  //at(1) index of element 0 to ~ expect(component.prop('title')).to.equal('Good-bye');