jest/prefer-comparison-matcher Style
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);
How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny jest/prefer-comparison-matcher --jest-plugin
json
{
"plugins": ["jest"],
"rules": {
"jest/prefer-comparison-matcher": "error"
}
}