Jest: shared async code between test blocks

dimaip profile image Dmitri Pisarev 🇷🇺 ・1 min read

I want to remember this day as the first day I asked something at StackOverflow and receive a brilliant and non-trivial answer!

Check it out, a way to provision a group of tests with some test data asynchronously while getting some data from the provisioning process:

const setupTestContext = testContext => beforeAll(async () => {
  Object.assign(testContext, await setup());


describe('Some group of tests', async () => {
    const someData = {};


    test('Test1', async () => {
      // context is filled with data at this point
      const actual = myFunc(someData.x)



markdown guide