jest global beforeAll to run once for all tests?

Viewed 813

Is it possible for jest config setUp to run a beforeAll and afterAll once for all test files?

I have a database connection that i have set up before the tests are started and when the tests are finished i close the connection, this works for a single test file, but if i have multiple tests files, the connection to the database fails to close, because one of the test file is still using the connection,

so to clarify i want to a globalSetUp a beforeAll to run once before all test files, and an afterAll that runs once after all tests have finished? so i can have 1 database connection only across the tests? jest setup in package.json:

"jest": {
  "preset": "ts-jest",
  "testEnvironment": "node",
  "setupFilesAfterEnv": ["<rootDir>/test/setUpTests.ts"]
},

enter image description here

0 Answers
Related