title: Jest doesn't wait for async beforeAll to finish
body: <p>Im trying to test getting all users from my REST API.</p>
  
  <pre><code>describe('GET', () =&gt; {
      let userId;
  
      // Setup create the mock user
      beforeAll(async () =&gt; {
        //Create the user
        return await request
            .post(routes.users.create)
            .set('Accept', 'application/json')
            .send(TEST_USER_DATA)
            .then(res =&gt; userId = res.body.id)
      })
  
      // Clean up, deleting all the fake data that we created for this test suite
      afterAll(async () =&gt; {
        // Clean up, delete the user we created
       return await request.delete(routes.users.delete(userId));
      })
  
      it('should get all users', async () =&gt; {
        const usersResponse = await request
          .get(routes.users.getAll)
          .set('Accept', 'application/json')
          .expect(200)
          .expect('Content-Type', /json/);
        // Logs an empty array
        console.log(usersResponse.body);
  
        expect(usersResponse.status).to.equal(200);
        expect(Array.isArray(usersResponse.body)).to.be.true();
      });
  });
  </code></pre>
  
  <p>But it look as though my <code>it()</code> block doesn't wait for <code>beforeAll()</code> to finish, because <code>userResponse.body()</code> is just an empty array. But when I do the same think in Postman(e.g. Create a mock user, then get all users, it displays an array with the user that we created) so the problem is definitely not in the server-side.</p>
  
  <p>I've already tried writing my beforeAll block like that:</p>
  
  <pre><code>beforeAll(async () =&gt; {
        //Create the user
        return await new Promise((resolve) =&gt; {
          request
            .post(routes.users.create)
            .set('Accept', 'application/json')
            .send(TEST_USER_DATA)
            .then(res =&gt; userId = res.body.id)
            .then(() =&gt; resolve)
          })
      })
  </code></pre>
  
  <p>And like that:</p>
  
  <pre><code>beforeAll(async (done) =&gt; {
        //Create the user
        request
          .post(routes.users.create)
          .set('Accept', 'application/json')
          .send(TEST_USER_DATA)
          .then(res =&gt; userId = res.body.id)
          .then(() =&gt; done());
  })
  </code></pre>
  
  <p>But neither of them worked.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As @jonrsharpe suggested I changed my <code>beforeAll</code> a bit to check the response status, and that we actually created a user</p>
  
  <pre><code>beforeAll(async () =&gt; {
        //Create the user
        return await request
            .post(routes.users.create)
            .set('Accept', 'application/json')
            .send(TEST_USER_DATA)
            .expect(200)
            .then(res =&gt; {
                userId = res.body.id;
                // Log the correct user
                console.log(res.body);
            })
  })
  </code></pre>
  
  <p>And the <code>beforeAll</code> block doesn't fail, so the creation of a user by itself is working fine.</p>