DEV Community

Discussion on: Testing with Jest and TypeScript, the tricky parts

Collapse
 
ngryman profile image
Nicolas Gryman • Edited

TIL I learned:

import { mocked } from 'ts-jest/utils'
Enter fullscreen mode Exit fullscreen mode

Thanks for the tip! This is really helpful to avoid πŸ‘Šing against Typescript when manipulating mocks.

That's probably a matter of taste, but I think the mock implementation could be simplified to something like this:

import fetch, { Response } from 'node-fetch'

mocked(fetch).mockImplementation(
  async () =>
    <Response>{
      json: async () => {name: 'Luke Vader'}
    }
)
Enter fullscreen mode Exit fullscreen mode