Skip to content
← Back to rules

jest/no-test-prefixes Style

🛠️ An auto-fix is available for this rule.

作用

要求使用 .only.skip,而不是 fx

为什么这不好?

Jest 允许你选择如何定义聚焦测试和跳过测试, 并且每种方式都有多种组合:

  • only & skip: it.only, test.only, describe.only, it.skip, test.skip, describe.skip.
  • 'f' & 'x': fit, fdescribe, xit, xtest, xdescribe.

此规则强制使用 only & skip 列表中的用法。

示例

以下是此规则的错误代码示例:

javascript
fit("foo"); // 无效
fdescribe("foo"); // 无效
xit("foo"); // 无效
xtest("foo"); // 无效
xdescribe("foo"); // 无效

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["jest"],
  "rules": {
    "jest/no-test-prefixes": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["jest"],
  rules: {
    "jest/no-test-prefixes": "error",
  },
});
bash
oxlint --deny jest/no-test-prefixes --jest-plugin

版本

此规则于 v0.0.7 中添加。

参考资料