ts-jest-mock
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

Format code Release Test code Mutation testing badge Commitizen friendly semantic-release npm npm npm bundle size (minified) All Contributors

forthebadge forthebadge

ts-jest-mock

A way to get jest type definition infered automagically.

Pre-requisites

This library takes for granted that you have your tests setup with jest.

Usage

Directly in a test

import { createMock } from 'ts-jest-mock'
import { someFn } from 'module_a'

jest.mock('module_a')

describe('something', () => {
  it('some test', () => {
    const someFnMock = createMock(someFn)

    someFnMock.mockReturnValue('') <-- Type inference yay :)
  })
})

Or with a beforeEach pattern

import { createMock } from 'ts-jest-mock'
import { someFn } from 'module_a'

jest.mock('module_a')

const someFnMock = createMock(someFn)

describe('something', () => {
  beforeEach(() => {
    someFnMock.mockReturnValue('') <-- Type inference yay :)
  })

  it('some test', () => {
    expect(someFnMock).toBe('')
  })
})

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Lucien Bénié
Lucien Bénié

💻 📖
Sébastien Dufour-Beauséjour
Sébastien Dufour-Beauséjour

💻
Ryan Ong
Ryan Ong

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Package Sidebar

Install

npm i ts-jest-mock

Weekly Downloads

15,211

Version

1.4.1

License

MIT

Unpacked Size

8.08 kB

Total Files

6

Last publish

Collaborators

  • lbenie