jest/prefer-spy-on
eslint-plugin-jest
Safe autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/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.
jest/prefer-spy-on
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-spy-on": "error",
},
},
];jest/prefer-spy-on
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/prefer-spy-on": "error"
}
}nursery/useSpyOn
nursery · since 2.6.8
{
"linter": {
"rules": {
"nursery": {
"useSpyOn": "error"
}
}
}
}Suggest having hooks before any test cases