prefer-comparison-matcher
Configuration
Rule Details
Prefer Jest's built-in comparison matchers over wrapping a relational operator in
expect(...).toBe(true) (or toEqual / toStrictEqual).
Assertions such as expect(x > 5).toBe(true) are harder to read and produce less
helpful failure output than expect(x).toBeGreaterThan(5).
This rule reports expect(left OP right).<equalityMatcher>(true|false) patterns
that can use one of these matchers instead:
toBeGreaterThantoBeGreaterThanOrEqualtoBeLessThantoBeLessThanOrEqual
Violations are automatically fixed where possible.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
String comparisons. These matchers only accept numbers and bigints. The rule
assumes operands are numeric and does not report comparisons that involve string
literals (for example, expect(x < 'Carl').toBe(true)). If you intentionally
compare strings with > or <, disable the rule for that line—otherwise the
fix rewrites the assertion to a numeric matcher and fails at runtime: