jest/no-untyped-mock-factory
eslint-plugin-jest
Safe autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-untyped-mock-factory": "error",
},
},
];Disallow using jest.mock() factories without an explicit type parameter
jest.mock('../moduleName', () => {
return jest.fn(() => 42);
});
jest.mock('./module', () => ({
...jest.requireActual('./module'),
foo: jest.fn(),
}));
jest.mock('random-num', () => {
return jest.fn(() => 42);
});// Uses typeof import()
jest.mock<typeof import('../moduleName')>('../moduleName', () => {
return jest.fn(() => 42);
});
jest.mock<typeof import('./module')>('./module', () => ({
...jest.requireActual('./module'),
foo: jest.fn(),
}));
// Uses custom type
jest.mock<() => number>('random-num', () => {
return jest.fn(() => 42);
});
// No factory
jest.mock('random-num');
// Virtual mock
jest.mock(
'../moduleName',
() => {
return jest.fn(() => 42);
},
{ virtual: true },
);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/no-untyped-mock-factory
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-untyped-mock-factory": "error",
},
},
];jest/no-untyped-mock-factory
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/no-untyped-mock-factory": "error"
}
}Biome does not have this rule.
Disallow unnecessary async function wrapper for expected promises
Enforce padding around afterAll blocks
Enforce padding around afterEach blocks