Skip to content
← Back to rules

jest/no-test-prefixes 风格

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"); // 无效

此规则与 eslint-plugin-vitest 兼容,要使用它,请在你的 .oxlintrc.json 中添加以下配置:

json
{
  "rules": {
    "vitest/no-test-prefixes": "error"
  }
}

如何使用

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

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

参考资料