jest/valid-title 正确性
它的作用
检查 Jest 和 Vitest 块的标题是否有效。
标题必须:
- 不能为空,
- 是字符串,
- 不能以前缀形式包含其块名称,
- 不能有前导或尾随空格。
为什么这不好?
无效的标题可能会造成误导,并使测试目的更难理解。
示例
以下是此规则的错误代码示例:
javascript
describe("", () => {});
describe("foo", () => {
it("", () => {});
});
it("", () => {});
test("", () => {});
xdescribe("", () => {});
xit("", () => {});
xtest("", () => {});以下是此规则的正确代码示例:
javascript
describe("foo", () => {});
it("bar", () => {});
test("baz", () => {});选项
typescript
interface Options {
ignoreSpaces?: boolean;
ignoreTypeOfTestName?: boolean;
ignoreTypeOfDescribeName?: boolean;
allowArguments?: boolean;
disallowedWords?: string[];
mustNotMatch?: Partial<Record<"describe" | "test" | "it", string>> | string;
mustMatch?: Partial<Record<"describe" | "test" | "it", string>> | string;
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["jest"],
"rules": {
"jest/valid-title": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["jest"],
rules: {
"jest/valid-title": "error",
},
});bash
oxlint --deny jest/valid-title --jest-plugin版本
此规则是在 v0.0.14 中添加的。
