TypeScript · testing
no-unsafe-mock-casting
eslint:no-unsafe-mock-casting Disallow casting to mock types like `jest.Mock` or `vi.Mock`. Use `vi.mocked()` or `jest.mocked()` instead.
- Default
- error
- Fix
- none
- Languages
- typescript
Why
A type assertion can claim an unmocked value is a mock and bypass checking between the original callable and the mock API.
Fix
Use the test framework's `mocked` helper to obtain the typed mock reference.
Before / after
Executed by this rule’s unit tests.
Before
Do not assert that a value is a mock
import type * as vi from "vitest"; const m = myFn as vi.Mock; After
Use the framework helper
const m = vi.mocked(myFn); Limits
- Only mock types imported from Vitest or Jest modules are inspected.
Message IDs
unsafeMockCast