# ts-jest-mock

> Maps to the proper jest mock type

Latest version **1.4.2** (published 2024-09-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-jest-mock
pnpm add ts-jest-mock
yarn add ts-jest-mock
bun add ts-jest-mock
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.4.2 |
| Published | 2024-09-02 |
| First published | 2021-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Lucien Bénié |
| Maintainers | lbenie |
| Keywords | jest, mock, mocks, unit, unit test, ut, test, ts, typescript |

## Links

- npm: https://www.npmjs.com/package/ts-jest-mock
- Repository: https://github.com/lbenie/ts-jest-mock
- Homepage: https://github.com/lbenie/ts-jest-mock#readme
- Issues: https://github.com/lbenie/ts-jest-mock/issues
- npm.io page: https://npm.io/package/ts-jest-mock

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.4.2 (latest) — 2024-09-02
- 1.4.1 — 2024-03-19
- 1.4.0 — 2024-02-02
- 1.3.0 — 2023-06-20
- 1.2.1 — 2023-03-22
- 1.2.0 — 2023-03-22
- 1.1.33 — 2022-06-21
- 1.1.32 — 2022-03-25
- 1.1.31 — 2022-01-25
- 1.1.30 — 2022-01-23
- 1.1.29 — 2022-01-22
- 1.1.28 — 2022-01-21
- 1.1.27 — 2022-01-20
- 1.1.26 — 2022-01-19
- 1.1.25 — 2022-01-18
- … 27 more at https://npm.io/package/ts-jest-mock/versions

## 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-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

[![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)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://lbenie.xyz/"><img src="https://avatars.githubusercontent.com/u/7316046?v=4?s=100" width="100px;" alt="Lucien Bénié"/><br /><sub><b>Lucien Bénié</b></sub></a><br /><a href="https://github.com/lbenie/ts-jest-mock/commits?author=lbenie" title="Code">💻</a> <a href="https://github.com/lbenie/ts-jest-mock/commits?author=lbenie" title="Documentation">📖</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/SebDuf"><img src="https://avatars.githubusercontent.com/u/12822182?v=4?s=100" width="100px;" alt="Sébastien Dufour-Beauséjour"/><br /><sub><b>Sébastien Dufour-Beauséjour</b></sub></a><br /><a href="https://github.com/lbenie/ts-jest-mock/commits?author=SebDuf" title="Code">💻</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/ryanong"><img src="https://avatars.githubusercontent.com/u/206333?v=4?s=100" width="100px;" alt="Ryan Ong"/><br /><sub><b>Ryan Ong</b></sub></a><br /><a href="https://github.com/lbenie/ts-jest-mock/commits?author=ryanong" title="Code">💻</a></td>
    </tr>
  </tbody>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

---
_Source: https://npm.io/package/ts-jest-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
