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

159
Vistas
How to test knexjs in node?

I have a function that store data into database:

async function save(id, fields) {
  ...
  const exist = await knex('table').select('..').where({ id });

  if (exist) {
     await knex('table').update([...fields...]).where({ id });
  } else {
     await knex('table').insert([...fields...]);
  }
  ....
}

How I test this function? I searched in knex docs but got no answer there.

What are the best practices?

Should I connect to "test" database and execute the database? but I think in this case I'll need to update the schema and the data which is kind annoying.

Should I create transaction every time I change the database and undo after the test complete?

Maybe mock knex? but how I know if the type and the query is correct?

Something else?

about 4 years ago · Juan Pablo Isaza
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