TypeScript: Property 'mockImplementation' does not exist on type in Jest Test

Viewed 1292

I have this basically:

// Example.ts

class Example {
  returnSomething() {
    return false
  }
}

export default new Example()

Then in a TypeScript Jest test I have this:

// Example/__tests__/index.test.ts

jest.mock('Example', () => ({
  _esModule: true,
  returnSomething: jest.fn(() => true)
  isFeatureEnabled: jest.fn(),
}))

// then down below:
it('some test', () => {
  Example.returnSomething.mockImplementation(() => 'foo')
})

But I am getting that error:

Property 'mockImplementation' does not exist on type ...

How do I get the jest wrapped mock of the function to work properly in TypeScript for this test?

Is there anything better than this?

(Example.returnSomething as jest.Mock).mockImplementation(() => 'foo')
0 Answers
Related