vitest/prefer-spy-on
@vitest/eslint-plugin
Safe autofix
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-spy-on": "error",
},
},
];Date.now = jest.fn();Date.now = vi.fn(() => 10);window.fetch = jest.fn().mockResolvedValue(response);jest.spyOn(Date, "now");
jest.spyOn(Date, "now").mockImplementation(() => 10);
vi.spyOn(window, "fetch").mockResolvedValue(response);
const mock = jest.fn();
const mocks = { now: vi.fn() };Examples from the Biome 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-spy-on
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-spy-on": "error",
},
},
];vitest/prefer-spy-on
vitest plugin · style
{
"plugins": [
"vitest"
],
"rules": {
"vitest/prefer-spy-on": "error"
}
}nursery/useSpyOn
nursery · since 2.6.8
{
"linter": {
"rules": {
"nursery": {
"useSpyOn": "error"
}
}
}
}Enforce importing Vitest globals
Enforce having hooks before any test cases
Enforce using the built-in equality matchers