title: How do I "wait" until a component has updated (re-rendered) with Enzyme and Jest?
body: <p>I have a parent component that does the following:</p>
  <ol>
  <li>Generates a form with various <code>input</code> fields</li>
  <li>When the submit button is clicked, a <code>POST</code> request with the <code>&lt;form&gt;</code> data is made to the server using <code>axios</code></li>
  <li>If an <code>Error</code> response is returned, an error message is rendered inside a <code>&lt;span&gt;</code> element on the form</li>
  </ol>
  <p>I'm writing the following test for this scenario</p>
  <pre><code>import axios from 'axios';
  import { expect } from 'chai';
  import { mount } from 'enzyme';
  
  jest.mock('axios');
  
  it('displays an error when the submit fails', async () =&gt; {
    const wrapper = mount(&lt;MyComponent /&gt;);
  
    // Fill in form input fields with text (not shown)
    // ....
    // ....
  
    // Mock the axios `POST` call to return an error
    const errorResponse = { response: { data: { errors: [{ title: 'Some error' }] } } }
    axios.post.mockImplementationOnce(() =&gt; Promise.reject(errorResponse));
  
    // Click Submit and wait on the axios Promise to complete
    const submit = wrapper.find('.my-component__submit-btn').first();
    await submit.simulate('click');
  
    // Check if error was rendered on the form
    wrapper.update();
    const error = wrapper.find('.my-component__submit-error').first();
    expect(error).to.have.text('Some error'); // This fails!
  });
  </code></pre>
  <p>The last <code>expect()</code> fails - no error is set but I expect one to exist.</p>
  <p>However if I add an artificial delay via <code>setTimeout</code>, it passes. So clearly it's an issue where the React component tree does not update before the <code>expect()</code> checks it.</p>
  <p>Is there a clean way to &quot;wait&quot; on the React tree to re-render without using <code>setTimeout</code>?</p>
  <p>I thought <code>wrapper.update()</code> would do this, but it doesn't seem to.</p>
  <p>Thanks!</p>