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

310
Vistas
How to mock functions of a function?

I'm using simple-git in my script like this:

import simpleGit from 'simple-git'
const git = simpleGit()

const foo = async (): Promise<void> => {
  const tags: string = await git.tag({
    '--list': null,
    '--format': '%(objectname:short)'
  })
}

In my tests I need to mock out the git calls, which I'm doing this way:

jest.mock('simple-git', () => ({
  tag: () => jest.fn()
}))

But this is failing. I guess, I have to take care of const git = simpleGit()

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If simple-git is installed via node_module (which I assume it is) you only need to create a directory called __mocks__ at the root of your project anything placed there is automatically mocked in your case you need to create a file called simple-git.js

.
├── __mocks__
│   └── simple-git.js
├── node_modules

Reference: https://jestjs.io/docs/manual-mocks#mocking-node-modules

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