跳至內容

jest/prefer-comparison-matcher 風格

🛠️ 此規則提供自動修復功能。

此規則的作用

此規則會檢查測試中可以被以下內建比較匹配器取代的比較

  • toBeGreaterThan
  • toBeGreaterThanOrEqual
  • toBeLessThan
  • toBeLessThanOrEqual

範例

js
// invalid
expect(x > 5).toBe(true);
expect(x < 7).not.toEqual(true);
expect(x <= y).toStrictEqual(true);
js
// valid
expect(x).toBeGreaterThan(5);
expect(x).not.toBeLessThanOrEqual(7);
expect(x).toBeLessThanOrEqual(y);
// special case - see below
expect(x < "Carl").toBe(true);

參考資料

以 MIT 授權釋出。