Jest run async function ONCE before all tests

This feature was added in Jest’s 22 version, with globalSetup and globalTeardown configurations.
Look at this for examples.

package.json (or in jest.config.js)

{
  ...
  "jest": {
    "globalSetup": "./scripts/jestGlobalSetup.js"
  }
}

/scripts/jestGlobalSetup.js

module.exports = async () => {
  console.log('\nhello, this is just before tests start running');
};

OR

export default async () => {
  console.log('\nhello, this is just before tests start running');
};

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)