1

I have a javascript project with jsconfig.json configured properly. It works for almost everything except for when I mock a module with jest.mock() on my unit tests:

// unit.test.js

jest.mock('./api')

it('does something', () => {
  // Linting error:  
  // Property 'mockResolvedValue' does not exist on type () => Promise<any>
  api.loadStudents.mockResolvedValue([]);
});

Is there any way to let TSServer know that Jest is mocking this module, so the exported object properties are instances of jest.Mock?

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
  • I'm not sure if you found the solution to this yet, but I ran across a [duplicate question](https://stackoverflow.com/questions/51495473/typescript-and-jest-avoiding-type-errors-on-mocked-functions) that solves this problem. In a nutshell, you create a new reference to the thing you're mocking (`api`) that you explicitly typecast as of type `jest.Mocked<...>`. – Mark Aug 08 '19 at 11:25
  • The thing is, I'm not using Typescript. I'm using Javascript with the `jsconfig.json` – Christopher Francisco Aug 08 '19 at 13:24
  • Ah, sorry. I misread your question. – Mark Aug 10 '19 at 11:53

0 Answers0