vitest/prefer-called-times
@vitest/eslint-plugin
Safe autofix
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-called-times": "error",
},
},
];test('foo', () => {
const mock = vi.fn()
mock('foo')
expect(mock).toBeCalledOnce()
expect(mock).toHaveBeenCalledOnce()
})test('foo', () => {
const mock = vi.fn()
mock('foo')
expect(mock).toBeCalledTimes(1)
expect(mock).toHaveBeenCalledTimes(1)
})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-times
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-called-times": "error",
},
},
];vitest/prefer-called-times
vitest plugin · style
{
"plugins": [
"vitest"
],
"rules": {
"vitest/prefer-called-times": "error"
}
}nursery/noExpectToHaveBeenCalledOnce
nursery · since 2.6.9
{
"linter": {
"rules": {
"nursery": {
"noExpectToHaveBeenCalledOnce": "error"
}
}
}
}Disallow return statements in tests
Enforce using toBeCalledWith() or toHaveBeenCalledWith()
Enforce using a function as a describe title over an equivalent string
Disallow duplicate hooks and teardown hooks
Enforce using the built-in equality matchers