vitest/prefer-import-in-mock
@vitest/eslint-plugin
Safe autofix
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-import-in-mock": "error",
},
},
];vi.mock('./path/to/module')
vi.doMock('./path/to/module')vi.mock(import('./path/to/module'))
vi.doMock(import('./path/to/module'))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.
vitest/prefer-import-in-mock
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-import-in-mock": "error",
},
},
];vitest/prefer-import-in-mock
vitest plugin · style
{
"plugins": [
"vitest"
],
"rules": {
"vitest/prefer-import-in-mock": "error"
}
}Biome does not have this rule.
Enforce using expect(...).toBeTypeOf(...) instead of expect(typeof ...).toBe(...)
Enforce mock resolved/rejected shorthands for promises
Enforce using expect().resolves over expect(await ...) syntax
Enforce using expect assertions instead of callbacks
Enforce including a hint with external snapshots