completed

ts-jest-mock

A way to get jest type definition inferred automagically.

  • TypeScript
  • ts-jest
  • jest
  • unit test

ts-jest-mock

It is a library to help writing unit tests using jest and TypeScript. With the createMock helper, you will be able to automatically infer the values when using all the .mock functions when using mocks.

For example, let’s say myAwesomeThing is a function that returns a number.

import { myAwesomeThing } from 'my-awesome-module'
import { createMock } from 'ts-jest-mock'

jest.mock('my-awesome-module')

const myAwesomeThingMock = createMock(myAwesomeThing)

describe('some describe', () => {
  it('test something', () => {
    myAwesomeThingMock.mockReturnValue(4)
    expect(myAwesomeThing()).toBe(4)
  })
})