Vyhledávání na webu

jestjs - TypeScript: Vlastnost 'mockImplementation' neexistuje u typu v testu Jest


Mám to v podstatě takto:

// Example.ts

class Example {
  returnSomething() {
    return false
  }
}

export default new Example()

Pak v testu TypeScript Jest mám toto:

// 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')
})

Ale dostávám tuto chybu:

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

Jak mohu správně využít jestem obalený mock funkce v TypeScriptu pro tento test?

Existuje něco lepšího než toto?

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

Související články