Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda