Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!