Jest clean up after all tests have run

There’s a sibling hook to setupFiles that will too fire before every test suite but right after your test runner (by default Jasmine2) has initialised global environment.

It’s called setupFilesAfterEnv. Use it like this:

{
    "setupFilesAfterEnv": ["<rootDir>/setup.js"]
}

Example setup.js:

beforeAll(() => console.log('beforeAll'));
afterAll(() => console.log('afterAll'));

setup.js doesn’t need to export anything. It will be executed before every test suite (every test file). Because test runner is already initialised, global functions like beforeAll and afterAll are in the scope just like in your regular test file so you can call them as you like.

setupTestFrameworkScriptFile firing beforeAll and afterAll

Leave a Comment

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