title: React Testing Library does not find elements using getAllByTestId after initial render
body: <p>I have a very simple component where I am trying to simulate an API call to get some movies with a slight delay.</p>
  <p>I want to write a test which tests that the movies are gathered and then rendered to screen.</p>
  <p>I am trying to use <code>screen.getAllByTestId</code> to do this, however it always fails.  It is as if it doesn't re-render and therefore does not get the updated change.</p>
  <p>I have added a testid onto the elements and can see these in the DOM.</p>
  <p>Can anyone help as to why this isn't finding them after they appear?</p>
  <p><a href="https://i.stack.imgur.com/3mSJq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3mSJq.png" alt="enter image description here" /></a></p>
  <p>Here is the full component code...</p>
  <pre class="lang-js prettyprint-override"><code>import './App.css';
  import { useEffect, useState } from 'react';
  
  function App() {
    const [movies, setMovies] = useState([]);
  
    useEffect(() =&gt; {
      // simulate API call to get
      setTimeout(() =&gt; {
        const movies = [{ title: 'Titanic' }, { title: 'Back To The Future' }];
        setMovies(movies);
      }, 1000);
    }, []);
  
    return (
      &lt;div&gt;
        {movies.length &gt; 0 &amp;&amp; (
          &lt;div&gt;
            {movies.map((x) =&gt; (
              &lt;div data-testid='movies'&gt;{x.title}&lt;/div&gt;
            ))}
          &lt;/div&gt;
        )}
      &lt;/div&gt;
    );
  }
  
  export default App;
  </code></pre>
  <p>Here is the full test code...</p>
  <pre class="lang-js prettyprint-override"><code>import { render, screen } from '@testing-library/react';
  import App from './App';
  
  test('renders learn react link', () =&gt; {
    render(&lt;App /&gt;);
    const movieTiles = screen.getAllByTestId('movies');
    expect(movieTiles).toHaveLength(2);
  });
  
  </code></pre>
  <p>Here is the error from the test</p>
  <p><a href="https://i.stack.imgur.com/REZL9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/REZL9.png" alt="enter image description here" /></a></p>