# prefer-to-be

Rule `jest/prefer-to-be`. Suggest using `toBe()` for primitive literals

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

## Linters

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

## Enable it

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

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

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

### Oxlint: `.oxlintrc.json`

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

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Jest style](https://lintradar.dev/presets/jest-style.md) | ESLint | `eslint-plugin-jest` | 3 | 16.7M | +10.1% |

## Related rules

- [vitest/prefer-to-be](https://lintradar.dev/rules/vitest/prefer-to-be.md): Enforce using toBe()
- [jest/prefer-to-have-length](https://lintradar.dev/rules/jest/prefer-to-have-length.md): Suggest using `toHaveLength()`
- [jest/prefer-to-contain](https://lintradar.dev/rules/jest/prefer-to-contain.md): Suggest using `toContain()`
- [jest/consistent-test-it](https://lintradar.dev/rules/jest/consistent-test-it.md): Enforce `test` and `it` usage conventions
- [jest/max-nested-describe](https://lintradar.dev/rules/jest/max-nested-describe.md): Enforces a maximum depth to nested describe calls
- [jest/no-hooks](https://lintradar.dev/rules/jest/no-hooks.md): Disallow setup and teardown hooks

---

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