# prefer-to-be

Rule `vitest/prefer-to-be`. Enforce using toBe()

- Source: vitest
- 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: #1802 by reach

## Linters

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

## Code examples

### Incorrect: the rule reports this

```ts
import { test } from 'vitest'

test('foo', () => {
  expect(1).toEqual(1)
})
```

### Correct: the rule accepts this

```ts
import { test } from 'vitest'

test('foo', () => {
  expect(1).toBe(1)
})
```

Examples from the ESLint documentation.

## Enable it

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

```js
import vitest from "@vitest/eslint-plugin";

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

### Oxlint: `.oxlintrc.json`

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

## Related rules

- [jest/prefer-to-be](https://lintradar.dev/rules/jest/prefer-to-be.md): Suggest using `toBe()` for primitive literals
- [vitest/prefer-strict-boolean-matchers](https://lintradar.dev/rules/vitest/prefer-strict-boolean-matchers.md): Enforce using `toBe(true)` and `toBe(false)` over matchers that coerce types to boolean
- [vitest/prefer-to-be-falsy](https://lintradar.dev/rules/vitest/prefer-to-be-falsy.md): Enforce using toBeFalsy()
- [vitest/prefer-snapshot-hint](https://lintradar.dev/rules/vitest/prefer-snapshot-hint.md): Enforce including a hint with external snapshots
- [vitest/prefer-to-be-object](https://lintradar.dev/rules/vitest/prefer-to-be-object.md): Enforce using toBeObject()
- [vitest/prefer-mock-return-shorthand](https://lintradar.dev/rules/vitest/prefer-mock-return-shorthand.md): Prefer mock return shorthands

---

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