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.