Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda