# prefer-comparison-matcher

Rule `jest/prefer-comparison-matcher`. Suggest using the built-in comparison matchers

- Source: jest
- Technologies: Testing
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1753 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/prefer-comparison-matcher` | no | safe | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/prefer-comparison-matcher.md) |
| Oxlint | `jest/prefer-comparison-matcher` | no | safe | plugin `jest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-comparison-matcher.html) |

## Code examples

### Incorrect: the rule reports this

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

### Correct: the rule accepts this

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

// special case - see below
expect(x < 'Carl').toBe(true);
```

```js
expect(myName).toBeGreaterThanOrEqual(theirName); // Matcher error: received value must be a number or bigint
```

```js
// eslint-disable-next-line jest/prefer-comparison-matcher
expect(myName > theirName).toBe(true);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import jest from "eslint-plugin-jest";

export default [
  {
    plugins: { jest },
    rules: {
      "jest/prefer-comparison-matcher": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "jest"
  ],
  "rules": {
    "jest/prefer-comparison-matcher": "error"
  }
}
```

## Related rules

- [vitest/prefer-comparison-matcher](https://lintradar.dev/rules/vitest/prefer-comparison-matcher.md): Enforce using the built-in comparison matchers
- [jest/padding-around-test-blocks](https://lintradar.dev/rules/jest/padding-around-test-blocks.md): Enforce padding around `test` and `it` blocks
- [jest/prefer-each](https://lintradar.dev/rules/jest/prefer-each.md): Prefer using `.each` rather than manual loops
- [jest/padding-around-expect-groups](https://lintradar.dev/rules/jest/padding-around-expect-groups.md): Enforce padding around `expect` groups
- [jest/prefer-ending-with-an-expect](https://lintradar.dev/rules/jest/prefer-ending-with-an-expect.md): Prefer having the last statement in a test be an assertion
- [jest/padding-around-describe-blocks](https://lintradar.dev/rules/jest/padding-around-describe-blocks.md): Enforce padding around `describe` blocks

---

Web page: https://lintradar.dev/rules/jest/prefer-comparison-matcher. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
