Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 1.54 KB

File metadata and controls

57 lines (40 loc) · 1.54 KB

vitest/prefer-import-in-mock

📝 Prefer dynamic import in mock.

⚠️ This rule warns in the 🌐 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.

Rule details

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'))

Options

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 }],
    },
  },
]