Skip to content

jest/prefer-comparison-matcher Style

🛠️ An auto-fix is available for this rule.

What it does

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

  • toBeGreaterThan
  • toBeGreaterThanOrEqual
  • toBeLessThan
  • toBeLessThanOrEqual

Examples

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);

References

Released under the MIT License.