title: React Testing Library's waitFor not working
body: <p>I am using <a href="https://testing-library.com/docs/guide-disappearance/#2-using-waitfor" rel="noreferrer">React Testing Library</a> to unit test my ReactJS code. There are several async events in the UI, like fetching data and displaying a new page on click of button. The React code is somewhat like this:</p>
  <pre><code>// Inside ParentComponent.tsx
  const [isChildVisible, setChildVisibility] = useState(false);
  const showChild = () =&gt; setChildVisibility(true);
  
  return(
    &lt;&gt;
        &lt;button data-testid=&quot;show-child&quot; onClick={showChild}&gt;Show Child&lt;/button&gt;
        {isChildVisible &amp;&amp; &lt;ChildComponent {..childProps}/&gt;}
   &lt;/&gt;
  )
  </code></pre>
  <p>Where <code>ChildComponent</code> mounts, it fetches some data and then re-renders itself with the hydrated data. My unit test looks like:</p>
  <pre><code>jest.mock('../../../src/service'); // mock the fetch functions used by ChildComponent to fetch its data
  
  describe('ParentComponent', () =&gt; {
      test('renders ChildComponent on button click', async () =&gt; {
          const screen = render(&lt;ParentComponent /&gt;);
          userEvent.click(screen.getByTestId('show-child'));
          await (waitFor(() =&gt; screen.getByText('text rendered by child')));
      });
  });
  </code></pre>
  <p>When I run this test, I get the error <code>&quot;TestingLibraryElementError: Unable to find an element with the text: text rendered by child. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.&quot;</code>.</p>
  <p>I am not sure why it's happening, but one of the reason maybe that it's taking more than one second to hydrate and render the child component. Thus I want to change the default wait time for <code>waitFor</code>, but I can't find a way to do it from the docs (the default wait time is one second). So is it possible to change the default wait time?</p>
  <p>EDIT: Increasing the wait time is still causing the same error. So the issue is something else.</p>