title: When testing, code that causes React state updates should be wrapped into act
body: <p>I have this test:</p>
  
  <pre><code>import {
    render,
    cleanup,
    waitForElement
  } from '@testing-library/react'
  
  const TestApp = () =&gt; {
    const { loading, data, error } = useFetch&lt;Person&gt;('https://example.com', { onMount: true });
  
    return (
      &lt;&gt;
        {loading &amp;&amp; &lt;div data-testid="loading"&gt;loading...&lt;/div&gt;}
        {error &amp;&amp; &lt;div data-testid="error"&gt;{error.message}&lt;/div&gt;}
        {data &amp;&amp; 
          &lt;div&gt;
            &lt;div data-testid="person-name"&gt;{data.name}&lt;/div&gt;
            &lt;div data-testid="person-age"&gt;{data.age}&lt;/div&gt;
          &lt;/div&gt;
        }
      &lt;/&gt;
    );
  };
  
    describe("useFetch", () =&gt; {
      const renderComponent = () =&gt; render(&lt;TestApp/&gt;);
  
      it('should be initially loading', () =&gt; {
        const { getByTestId } = renderComponent();
  
        expect(getByTestId('loading')).toBeDefined();
      })
    });
  </code></pre>
  
  <p>The test passes but I get the following warning:</p>
  
  <blockquote>
    <p>Warning: An update to TestApp inside a test was not wrapped in
    act(...).</p>
  
  <pre><code>When testing, code that causes React state updates should be wrapped into act(...):
  
  act(() =&gt; {
    /* fire events that update state */
  });
  /* assert on the output */
  
  This ensures that you're testing the behavior the user would see in the browser
      in TestApp
  </code></pre>
    
    <p>console.error
    node_modules/react-dom/cjs/react-dom.development.js:506
        Warning: An update to TestApp inside a test was not wrapped in act(...).</p>
  
  <pre><code>When testing, code that causes React state updates should be wrapped into act(...):
  
  act(() =&gt; {
    /* fire events that update state */
  });
  /* assert on the output */
  
  This ensures that you're testing the behavior the user would see in the browser
      in TestApp
  </code></pre>
  </blockquote>