ts-jest-mock
v1.4.2
Published
Maps to the proper jest mock type
Downloads
94,163
Maintainers
Readme
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):
This project follows the all-contributors specification. Contributions of any kind welcome!