A way to get jest type definition infered automagically.
This library takes for granted that you have your tests setup with jest
.
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('')
})
})
Thanks goes to these wonderful people (emoji key):
Lucien Bénié 💻 📖 |
Sébastien Dufour-Beauséjour 💻 |
Ryan Ong 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!