Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lbenie/ts-jest-mock
A type definition and helper for jest mocks in TypeScript
https://github.com/lbenie/ts-jest-mock
jest testing typescript
Last synced: 26 days ago
JSON representation
A type definition and helper for jest mocks in TypeScript
- Host: GitHub
- URL: https://github.com/lbenie/ts-jest-mock
- Owner: lbenie
- License: mit
- Created: 2021-03-18T16:36:27.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-26T03:54:45.000Z (about 1 month ago)
- Last Synced: 2024-12-26T04:27:58.540Z (about 1 month ago)
- Topics: jest, testing, typescript
- Language: TypeScript
- Homepage:
- Size: 4.35 MB
- Stars: 13
- Watchers: 3
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/funding.yml
- License: LICENSE
Awesome Lists containing this project
README
[![Format code](https://github.com/lbenie/ts-jest-mock/actions/workflows/format.yml/badge.svg)](https://github.com/lbenie/ts-jest-mock/actions/workflows/format.yml)
[![Release](https://github.com/lbenie/ts-jest-mock/actions/workflows/release.yml/badge.svg)](https://github.com/lbenie/ts-jest-mock/actions/workflows/release.yml)
[![Test code](https://github.com/lbenie/ts-jest-mock/actions/workflows/test.yml/badge.svg)](https://github.com/lbenie/ts-jest-mock/actions/workflows/test.yml)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Flbenie%2Fts-jest-mock%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/lbenie/ts-jest-mock/main)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![npm](https://img.shields.io/npm/l/ts-jest-mock.svg)](https://github.com/lbenie/ts-jest-mock/blob/master/LICENSE)
[![npm](https://img.shields.io/npm/dt/ts-jest-mock.svg)](https://www.npmjs.com/package/ts-jest-mock)
[![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/ts-jest-mock.svg)](https://www.npmjs.com/package/ts-jest-mock)
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/made-with-typescript.svg)](https://forthebadge.com)# 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
```ts
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
```ts
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](https://allcontributors.org/docs/en/emoji-key)):
Lucien Bénié
💻 📖
Sébastien Dufour-Beauséjour
💻
Ryan Ong
💻
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!