跳至內容

jest/expect-expect 正確性

作用

當測試中沒有呼叫 expect 時,此規則會觸發,確保測試中至少有一個 expect 呼叫。

為什麼這樣不好?

人們可能會忘記添加斷言。

範例

javascript
it("should be a test", () => {
  console.log("no assertion");
});
test("should assert something", () => {});

此規則與 eslint-plugin-vitest 相容,若要使用它,請將以下設定新增到您的 .eslintrc.json

json
{
  "rules": {
    "vitest/expect-expect": "error"
  }
}

參考資料

以 MIT 許可證發布。