vitest/valid-expect
@vitest/eslint-plugin
Safe autofixRecommended
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/valid-expect": "error",
},
},
];expect(Promise.resolve(1)).resolves.toBe(1)
expect(Promise.reject(1)).rejects.toBe(1)expect().toBe(1)
expect(1).toBe()expect(1, 2, 3, 4).toBe(1)await expect(Promise.resolve(1)).resolves.toBe(1)
await expect(Promise.reject(1)).rejects.toBe(1)expect(1).toBe(1)
expect(1, 2).toBe(1)
expect(1, 2, 3).toBe(1)expect(1).toBe(1)
expect(1, 'expect value to be one').toBe(1)
const message = 'expect value to be one'
expect(1, `Error Message: ${message}`).toBe(1)Examples from the ESLint documentation.
vitest/valid-expect
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/valid-expect": "error",
},
},
];vitest/valid-expect
vitest plugin · correctness
{
"plugins": [
"vitest"
],
"rules": {
"vitest/valid-expect": "error"
}
}Biome does not have this rule.
Require promises that have expectations in their chain to be valid
Require local Test Context for concurrent snapshot tests
Prefer toHaveBeenCalledExactlyOnceWith over toHaveBeenCalledOnce and toHaveBeenCalledWith
Disallow unnecessary async function wrapper for expected promises