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