Skip to content

BuZZ-T/eslint-plugin-jest-mock-config

Repository files navigation

eslint-plugin-jest-mock-config

NPM Version Package License GitHub Actions Workflow Status

ESLint rules for mocking in jest using jest.mock(...).

Rules

This Plugin currently contains the following ESLint rules:

Name Description Documentation
Rules showing errors
jest-mock-without-import Reports jest.mock(<path>), when no import of <path> exists Link
jest-mocked-without-mock Reports jest.mocked(<function>), when the import of <function> is not mocked via jest.mock Link
jest-mock-multiple-with-same-path Reports, if jest.mock(<path>) is used multiple times with the same path in one file Link
Layouting rules
jest-mock-directly-above-jest-mocked Reports, if a jest.mock() call and its corresponding jest.mocked call don't come directly after each other. Conflicts with jest-mock-grouped and jest-mocked-grouped Link
jest-mock-grouped Reports, if not all jest.mock() calls come directly after each other. Conflicts with jest-mock-directly-above-jest-mocked Link
jest-mocked-grouped Reports, if not all jest.mocked() calls come directly after each other. Conflicts with jest-mock-directly-above-jest-mocked Link

Installation

# npm
npm install --safe-dev eslint-plugin-jest-mock-config

#yarn
yarn add --dev eslint-plugin-jest-mock-config

Development

Tests

npm test

Usage

When to use the plugin

If you are using jest with JavaScript or TypeScipt for your tests and want to detect wrong configurations of your jest mocks.

When to not use the plugin

If you are not using jest in your project

ESLint7 / 8 / 9 compatibility

Rules included in this ESLint plugin are tested with Version 7 / 8 and 9 of ESLint. See the github actions testing all rules for eslint7, 8 and 9 and the related (stub-) projects localed in examples.

Please report bugs here, if you still encounter some!

About

eslint rules for paths in jest.mock()

Resources

License

Stars

Watchers

Forks

Packages

No packages published