ESLint rules for mocking in jest
using jest.mock(...)
.
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 |
# npm
npm install --safe-dev eslint-plugin-jest-mock-config
#yarn
yarn add --dev eslint-plugin-jest-mock-config
npm test
If you are using jest with JavaScript or TypeScipt for your tests and want to detect wrong configurations of your jest mocks.
If you are not using jest in your project
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!