Skip to content

Rule to prevent having typecasts of jest.Mock instead of using directly jest.mocked()

Notifications You must be signed in to change notification settings

mattermost/eslint-plugin-ai-imports

Repository files navigation

eslint-plugin-ai-imports

An ESLint plugin that enforces using jest.mocked() instead of type casting with jest.Mock.

Installation

npm install eslint-plugin-ai-imports --save-dev

Usage

Add the plugin to your ESLint configuration:

// .eslintrc.js
module.exports = {
  plugins: ['ai-imports'],
  rules: {
    'ai-imports/jest-mocked': 'error'
  }
};

Rule Details

This rule aims to enforce using jest.mocked() instead of type casting with jest.Mock.

❌ Incorrect

(myMock as jest.Mock).mockImplementation(() => {});

✅ Correct

jest.mocked(myMock).mockImplementation(() => {});

Why?

Using jest.mocked() is the recommended approach in Jest for TypeScript projects. It provides proper type inference and is more readable than type casting.

About

Rule to prevent having typecasts of jest.Mock instead of using directly jest.mocked()

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published