Skip to main content

require-vitest-mock-reset-policy

Require at least one enabled Vitest mock reset policy (clearMocks, resetMocks, or restoreMocks).

Rule catalog ID: R053

Targeted pattern scopeโ€‹

  • vitest.config.*
  • vitest.workspace.*
  • vite.config.* when Vitest test options are configured
  • test.clearMocks
  • test.resetMocks
  • test.restoreMocks

What this rule reportsโ€‹

This rule reports test configurations that do not enable any of these policies as true:

  • clearMocks
  • resetMocks
  • restoreMocks

Why this rule existsโ€‹

Mock state can leak between tests when no reset/restore strategy is configured. A shared policy reduces nondeterminism and cross-suite interference.

โŒ Incorrectโ€‹

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
},
});

โœ… Correctโ€‹

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
restoreMocks: true,
},
});

Behavior and migration notesโ€‹

  • this rule checks static boolean values only
  • it reports once per test scope missing a mock reset policy

ESLint flat config exampleโ€‹

import vite from "@typpi/eslint-plugin-vite";

export default [vite.configs.strict, vite.configs.vitest];

When not to use itโ€‹

Disable this rule only if mock lifecycle is fully controlled elsewhere and this config intentionally omits those flags.

Package documentationโ€‹

Further readingโ€‹