vitest/prefer-called-once
@vitest/eslint-plugin
Safe autofix
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-called-once": "error",
},
},
];test('foo', () => {
const mock = vi.fn()
mock('foo')
expect(mock).toBeCalledTimes(1)
expect(mock).toHaveBeenCalledTimes(1)
})test('foo', () => {
const mock = vi.fn()
mock('foo')
expect(mock).toBeCalledOnce()
expect(mock).toHaveBeenCalledOnce()
})Examples from the ESLint 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-called-once
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-called-once": "error",
},
},
];vitest/prefer-called-once
vitest plugin · style
{
"plugins": [
"vitest"
],
"rules": {
"vitest/prefer-called-once": "error"
}
}Biome does not have this rule.
Enforce using the built-in comparison matchers
Enforce padding around expect groups
Enforce padding around describe blocks
Enforce using expect assertions instead of callbacks