jest/no-focused-tests Correctness
它的作用
当你使用排他性功能时,此规则会通过发出警告提醒你从测试中移除 .only。
为什么这不好?
Jest 提供了一项功能,可以通过在测试套件或测试用例后附加 .only,或者在前面加上 f 来聚焦测试。这个功能对于调试失败的测试非常有帮助,这样你就不必执行所有测试。在你修复测试之后,并且在提交更改之前,你必须移除 .only,以确保在你的构建系统上会执行所有测试。
示例
此规则的错误代码示例:
javascript
describe.only("foo", () => {});
it.only("foo", () => {});
describe["only"]("bar", () => {});
it["only"]("bar", () => {});
test.only("foo", () => {});
test["only"]("bar", () => {});
fdescribe("foo", () => {});
fit("foo", () => {});
fit.each`
table
`();如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["jest"],
"rules": {
"jest/no-focused-tests": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["jest"],
rules: {
"jest/no-focused-tests": "error",
},
});bash
oxlint --deny jest/no-focused-tests --jest-plugin版本
此规则是在 v0.0.8 中添加的。
