Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
jest global beforeAll to run once for all tests?

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!