vitest/expect-expect Correctness
它的作用
当测试中没有调用 expect 时,此规则会触发,确保测试中至少有一次 expect 调用。
为什么这不好?
人们可能会忘记添加断言。
示例
以下是此规则的错误代码示例:
javascript
it("should be a test", () => {
console.log("no assertion");
});
test("should assert something", () => {});配置
此规则接受一个配置对象,包含以下属性:
additionalTestBlockFunctions
type: string[]
default: []
应当也被视为测试块的函数名数组。
assertFunctionNames
type: string[]
default: ["expect"]
应当被视为断言函数的函数名列表。
注意:默认值在 Jest 中是 ["expect"],而在 Vitest 中是 ["expect", "expectTypeOf", "assert", "assertType"]。
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vitest"],
"rules": {
"vitest/expect-expect": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vitest"],
rules: {
"vitest/expect-expect": "error",
},
});bash
oxlint --deny vitest/expect-expect --vitest-plugin版本
此规则在 v0.0.12 中添加。
