Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 946 Bytes

File metadata and controls

36 lines (25 loc) · 946 Bytes

vitest/prefer-comparison-matcher

📝 Enforce using the built-in comparison matchers.

⚠️ This rule warns in the 🌐 all config.

🔧 This rule is automatically fixable by the --fix CLI option.

This rule checks for comparisons in a test that could be replaced with one of the following built-in comparison matchers:

  • toBeGreaterThan
  • toBeGreaterThanOrEqual
  • toBeLessThan
  • toBeLessThanOrEqual

Examples of incorrect code for this rule:

expect(x > 5).toBe(true)
expect(x < 7).not.toEqual(true)
expect(x <= y).toStrictEqual(true)

Examples of correct code for this rule:

expect(x).toBeGreaterThan(5)
expect(x).not.toBeLessThanOrEqual(7)
expect(x).toBeLessThanOrEqual(y)

// special case - see below
expect(x < 'Carl').toBe(true)
// Rule only works on inters and big integers