title: Async beforeAll() does not finish before beforeEach() is called
body: <p>In Jest, <code>beforeAll()</code> is supposed to run before <code>beforeEach()</code>.</p>
  <p>The problem is that when I use an async callback for <code>beforeAll()</code>, Jest doesn't wait for the callback to finish before going on to <code>beforeEach()</code>.</p>
  <p>How can I force Jest to wait for an async <code>beforeAll()</code> callback to finish before proceeding to <code>beforeEach()</code>?</p>
  <h3>Minimal reproducible example</h3>
  <p>tests/myTest.test.js</p>
  <pre><code>const connectToMongo = require('../my_async_callback')    
  
  // This uses an async callback.
  beforeAll(connectToMongo) 
  
  // This is entered before the beforeAll block finishes. =,(
  beforeEach(() =&gt; { 
    console.log('entered body of beforeEach')  
  })
  
  test('t1'), () =&gt; {
    expect(1).toBe(1)
  }
  test('t2'), () =&gt; {
    expect(2+2).toBe(4)
  }
  test('t3'), () =&gt; {
    expect(3+3+3).toBe(9)
  }
  </code></pre>
  <p>my_async_callback.js</p>
  <pre><code>const connectToMongo = async () =&gt; {
    try {
      await mongoose.connect(config.MONGODB_URI, { 
        useNewUrlParser: true, 
        useUnifiedTopology: true, 
        useFindAndModify: false, 
        useCreateIndex: true 
      })
      console.log('Connected to MongoDB')
    } catch (err) {
      console.log(`Error connecting to MongoDB: ${err.message}`)
    }
  }
  
  module.exports = connectToMongo
  </code></pre>
  <p><strong>UPDATE:</strong> As the accepted answer helpfully points out, Jest actually does wait for <code>beforeAll</code> to finish first, except in the case of a broken Promise chain or a timeout. So, the premise of my question is false. My <code>connectToMongo</code> function was timing out, and simply increasing the Jest timeout solved the problem.</p>