📝 Prefer dynamic import in mock.
all config.
🔧 This rule is automatically fixable by the --fix CLI option.
This rule enforces using a dynamic import() in vi.mock() and vi.doMock(), which improves type information and IntelliSense for the mocked module.
The following patterns are considered a warning:
vi.mock('./path/to/module')
vi.doMock('./path/to/module')The following patterns are not considered a warning:
vi.mock(import('./path/to/module'))
vi.doMock(import('./path/to/module'))| Name | Description | Type |
|---|---|---|
fixable |
Whether the rule should provide an autofix. | Boolean |
This rule has a fixable option that tells the plugin to automatically fix the imports for you.
The option is enabled by default. You can disable it in your eslint.config.js file using the following configuration.
import vitest from 'eslint-plugin-vitest'
export default [
{
files: ['**/*.ts', '**/*.js'], // or any other pattern
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.all,
'vitest/prefer-import-in-mock': ['error', { fixable: false }],
},
},
]