Skip to content

lint: enable jest/prefer-jest-mocked#115791

Merged
evanpurkhiser merged 1 commit into
masterfrom
evanpurkhiser/lint-add-no-jest-mock-cast-rule-to-replace-as-jest-mock-with-jest-mocked-
May 19, 2026
Merged

lint: enable jest/prefer-jest-mocked#115791
evanpurkhiser merged 1 commit into
masterfrom
evanpurkhiser/lint-add-no-jest-mock-cast-rule-to-replace-as-jest-mock-with-jest-mocked-

Conversation

@evanpurkhiser
Copy link
Copy Markdown
Member

@evanpurkhiser evanpurkhiser commented May 19, 2026

Enables jest/prefer-jest-mocked from eslint-plugin-jest (already a dep). It covers jest.Mock, jest.MockedFunction, jest.MockedClass, and jest.MockedObject assertions and autofixes to jest.mocked(). The five remaining offending files are fixed in this PR as well.

@evanpurkhiser evanpurkhiser requested review from a team as code owners May 19, 2026 14:19
@evanpurkhiser evanpurkhiser requested review from JoshuaKGoldberg, natemoo-re and scttcper and removed request for a team May 19, 2026 14:19
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 19, 2026
@evanpurkhiser evanpurkhiser enabled auto-merge (squash) May 19, 2026 14:21
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

📊 Type Coverage Diff

✅ No new type safety issues introduced. Coverage: 93.56%

Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,48 @@
import {ESLintUtils} from '@typescript-eslint/utils';

export const noJestMockCast = ESLintUtils.RuleCreator.withoutDocs({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for being a stickler, but in lint-land terminology a "cast" is a wholly different thing (runtime). Assertions are the type system feature. They're not technically interchangeable terms (even though everyone generally does in casual speak).

Suggested change
export const noJestMockCast = ESLintUtils.RuleCreator.withoutDocs({
export const noJestMockAssertion = ESLintUtils.RuleCreator.withoutDocs({

schema: [],
messages: {
noJestMockCast:
'Use `jest.mocked({{expression}})` instead of casting with `as jest.Mock`.',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Use `jest.mocked({{expression}})` instead of casting with `as jest.Mock`.',
'Use `jest.mocked({{expression}})` instead of asserting with `as jest.Mock`.',

@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/lint-add-no-jest-mock-cast-rule-to-replace-as-jest-mock-with-jest-mocked- branch from cd2dd54 to ed67da5 Compare May 19, 2026 14:43
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ed67da5. Configure here.

Comment thread static/eslint/eslintPluginScraps/src/rules/no-jest-mock-cast.ts Outdated
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/lint-add-no-jest-mock-cast-rule-to-replace-as-jest-mock-with-jest-mocked- branch from ed67da5 to b39419a Compare May 19, 2026 15:03
@evanpurkhiser
Copy link
Copy Markdown
Member Author

@JoshuaKGoldberg will update the terminology before merging this!

@evanpurkhiser evanpurkhiser disabled auto-merge May 19, 2026 16:05
@evanpurkhiser
Copy link
Copy Markdown
Member Author

Let me see if we can just use jest/prefer-jest-mocked if we have that already :)

….mocked()`

Enables jest/prefer-jest-mocked from eslint-plugin-jest, which covers
`jest.Mock`, `jest.MockedFunction`, `jest.MockedClass`, and
`jest.MockedObject` assertions and includes an autofix to jest.mocked().
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/lint-add-no-jest-mock-cast-rule-to-replace-as-jest-mock-with-jest-mocked- branch from b39419a to cb500e2 Compare May 19, 2026 21:43
@evanpurkhiser evanpurkhiser requested review from a team as code owners May 19, 2026 21:43
@evanpurkhiser evanpurkhiser changed the title lint: add no-jest-mock-cast rule to replace as jest.Mock with jest.mocked() lint: enable jest/prefer-jest-mocked May 19, 2026
@evanpurkhiser evanpurkhiser merged commit e9ec7d0 into master May 19, 2026
73 checks passed
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/lint-add-no-jest-mock-cast-rule-to-replace-as-jest-mock-with-jest-mocked- branch May 19, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants