Skip to content
← Back to rules

jest/no-focused-tests 正确性

An auto-fix is available for this rule.

它的作用

当您使用排他性功能时,此规则会通过发出警告提醒您移除测试中的 .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
`();

此规则与 eslint-plugin-vitest 兼容。要使用它,请将以下配置添加到您的 .oxlintrc.json 文件中:

json
{
  "rules": {
    "vitest/no-focused-tests": "error"
  }
}

如何使用

要通过配置文件或 CLI 启用 此规则,可以使用:

json
{
  "plugins": ["jest"],
  "rules": {
    "jest/no-focused-tests": "error"
  }
}
bash
oxlint --deny jest/no-focused-tests --jest-plugin

参考资料