React Testing Confusion

React Testing Confusion
0.0 0


When to use testutils functions like

to test components and when to use refs?

say we have parent Parent component and inside that is Child child component

const parent = renderIntoDocument(
         <Parent />

Now if we want to select Child child component I think, we have two options-

1. const child = scryRenderedComponentsWithType(parent, 'Child');
   const el = ReactDOM.findDOMNode(child[0]);

  2.  const child = voting.refs.someref;  ("Assuming we have a ref element on child component with value")
      const el = ReactDOM.findDOMNode(child)

My question is when to use first one and when to use second one and how to decide? Because in different situations both are not working same


Method 2 looks cleaner. No idea when you would use each. I have little experience with React.