Skip to content
← Back to rules

jest/no-test-return-statement Style

作用

禁止在测试中显式返回。

为什么这不好?

Jest 中的测试应当是 void,并且不应返回值。 如果你返回的是 Promise,那么你应该将测试更新为使用 async/await

示例

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

javascript
test("one", () => {
  return expect(1).toBe(1);
});

以下是此规则的 正确 代码示例:

javascript
test("one", () => {
  expect(1).toBe(1);
});

如何使用

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

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

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

版本

此规则是在 v0.2.0 中添加的。

参考