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

156
Views
Testing codebase functions with Jest

We export a "global" database object called db from a file called db.js. This file contains all the knex connection info. db is used across our system in basically every database interaction.

When adding Jest for testing, I realized that I needed to recreate a knex object in each test script and not use the global db object. However, the functions I want to test that are part of our system still use db. So, I get connection errors because it's not using the active connection which is established in the test script.

Is there a best practice or a straightforward way to test my system functions? Do I even need to recreate the connection in each script (I get connection errors if I don't)? Or do I need to add an argument to all the functions for the db object so that I can use my new connection?

Using Node, Jest, and Postgres. The "connection errors" I get are "role 'dan' does not exist", where 'dan' is my operating system login name.

about 4 years ago · Santiago Gelvez
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!