An ESLint plugin that enforces using jest.mocked()
instead of type casting with jest.Mock
.
npm install eslint-plugin-ai-imports --save-dev
Add the plugin to your ESLint configuration:
// .eslintrc.js
module.exports = {
plugins: ['ai-imports'],
rules: {
'ai-imports/jest-mocked': 'error'
}
};
This rule aims to enforce using jest.mocked()
instead of type casting with jest.Mock
.
(myMock as jest.Mock).mockImplementation(() => {});
jest.mocked(myMock).mockImplementation(() => {});
Using jest.mocked()
is the recommended approach in Jest for TypeScript projects. It provides proper type inference and is more readable than type casting.