jest/prefer-jest-mocked
eslint-plugin-jest
Safe autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-jest-mocked": "error",
},
},
];(foo as jest.Mock).mockReturnValue(1);
const mock = (foo as jest.Mock).mockReturnValue(1);
(foo as unknown as jest.Mock).mockReturnValue(1);
(Obj.foo as jest.Mock).mockReturnValue(1);
([].foo as jest.Mock).mockReturnValue(1);jest.mocked(foo).mockReturnValue(1);
const mock = jest.mocked(foo).mockReturnValue(1);
jest.mocked(Obj.foo).mockReturnValue(1);
jest.mocked([].foo).mockReturnValue(1);Examples from the Oxlint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
jest/prefer-jest-mocked
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-jest-mocked": "error",
},
},
];jest/prefer-jest-mocked
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/prefer-jest-mocked": "error"
}
}Biome does not have this rule.
Prefer await expect(...).resolves over expect(await ...) syntax
Prefer mock resolved/rejected shorthands for promises
Suggest using expect.assertions() OR expect.hasAssertions()
Prefer having the last statement in a test be an assertion
Prefer including a hint with external snapshots