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

997
Vistas
How can I mock Prisma client with es6 (Without typescript) in jest?

The Prisma Documentation has examples of mocking the client and doing unit testing using jest and typescript. Is there any way to mock the client in jest without using TypeScript?

I would be grateful if you can give a simple example.

Small Thing to add: I am using dependency injection in my project in all the functions that use the prisma.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

My solution for now: I am manually mocking the database object and passing it to the function that uses it: I am not sure how useful this but it helps avoid making calls to the real database.

const mocked_db = {
    user: {
        findFirst: jest.fn(() => Promise.resolve(
            {
                id: 2,
                first_name: "Basel",
                last_name: "Akasha"
            }
        ))
    }
}

it("It should work blah blah bla", async () => {
    let user_details= {
       id: 2,
       first_name: "Basel",
       last_name: "Akasha"
    }
    
    let signup = await getUser(
        mocked_db // takes thew DB object is a parameter (normally you would pass your Prisma client instance)
    )

    await expect(.... // whatever you'r expect is
})'
over 4 years ago · Santiago Trujillo Denunciar
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