Skip to content
← Back to rules

jest/expect-expect 正しさ

何を実行するか

テスト内で expect の呼び出しがない場合、このルールはトリガーされます。テスト内に少なくとも1回の expect 呼び出しを行うことを保証します。

なぜ問題なのか

アサーションを忘れてしまう可能性があるためです。

このルールに対して不正なコードの例:

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

このルールは eslint-plugin-vitest と互換性があります。 使用するには、.oxlintrc.json に以下の設定を追加してください:

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

設定

このルールは、次のプロパティを持つ設定オブジェクトを受け入れます:

additionalTestBlockFunctions

型: string[]

デフォルト: []

テストブロックとして扱われるべき関数名の配列です。

assertFunctionNames

型: string[]

デフォルト: ["expect"]

アサーション関数として扱われるべき関数名のリストです。

注釈: デフォルト値は Jest では ["expect"] で、Vitest では ["expect", "expectTypeOf", "assert", "assertType"] です。

使用方法

このルールを有効にするには、設定ファイルまたは CLI で以下を使用できます:

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

参照