ESLint rules for mocking using
This Plugin currently contains the following ESLint rules:
Name | Description | Documentation |
---|---|---|
jest-mock-without-import |
Reports jest.mock(<path>) , when no import of <path> exitsts |
Link |
jest-mocked-without-mock |
Reports jest.mocked(<function>) , when the import of <function> is not mocked via jest.mock |
Link |
# npm
npm install --safe-dev eslint-plugin-jest-mock-config
#yarn
yarn add --dev eslint-plugin-jest-mock-config
Of cource this works for absolute and relative paths. Decide on your own, if ignoring relative paths is useful!
npm test
If you are using jest with JavaScript or TypeScipt for your tests with .mockReturnValue
/ .mockResolvedValue
/ etc and want to detect wrong configurations of your jest mocks.
- If you are not using jest in your project
- If you are ONLY using jest without
.mockReturnValue
/.mockResolvedValue
/ etc. and just mocking the import of the file injest.mock
as second parameter, e.g.:
jest.mock('/some/path', () => ({ someFunction: () => { ... } }))
Rules included in this ESLint plugin are tested with Version 7 / 8 and 9 of ESLint. Please report bugs here, if you still encounter some.