Skip to content
← Back to rules

jest/prefer-todo 风格

An auto-fix is available for this rule.

它的作用

当测试用例为空时,将其标记为 test.todo 会更好,因为这样会在总结输出中被突出显示。

为什么这是不好的?

如果未使用 test.todo 而直接使用空的测试用例,此规则将触发警告。

示例

此规则的 错误 代码示例:

javascript
test("我需要编写这个测试"); // 无效
test("我需要编写这个测试", () => {}); // 无效
test.skip("我需要编写这个测试", () => {}); // 无效

此规则的 正确 代码示例:

javascript
test.todo("我需要编写这个测试");

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

json
{
  "rules": {
    "vitest/prefer-todo": "error"
  }
}

如何使用

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

json
{
  "plugins": ["jest"],
  "rules": {
    "jest/prefer-todo": "error"
  }
}
bash
oxlint --deny jest/prefer-todo --jest-plugin

参考资料