Skip to content

Files

Latest commit

 

History

History
23 lines (17 loc) · 598 Bytes

prefer-comparison-matcher.md

File metadata and controls

23 lines (17 loc) · 598 Bytes

Pattern: Comparison as boolean assertion

Issue: -

Description

Using boolean assertions for numeric comparisons is less readable than Jest's built-in comparison matchers. The matchers toBeGreaterThan, toBeGreaterThanOrEqual, toBeLessThan, and toBeLessThanOrEqual should be used instead.

Examples

Example of incorrect code:

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

Example of correct code:

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