title: React testing library - how to populate values in a state to test the component?
body: <p>My component -&gt;</p>
  <pre><code>export default()=&gt;{
  const [list, setList] = useState([])
  
   const handleAddToList = () =&gt; {
  //makes an api call and sets the list state.
  setList(response);
  }
  return (
  
  &lt;div&gt;
    &lt;Button onClick={hanldeAddToList}&gt;add to list&lt;/Button&gt;
  {
  list.map(row=&gt;&lt;span&gt;{row.name} &lt;/span&gt;)
  }
  &lt;/div&gt;
  )
  
  }
  </code></pre>
  <p><strong>Problem</strong> =&gt;</p>
  <p>how to test this component using React testing library with mock list data, the problem is &quot;list&quot; is a state here and I cant test it using react testing library because it doesn't focus on the implementation and therefore I cant populate list state.</p>