# prefer-to-contain

Rule `vitest/prefer-to-contain`. Enforce using toContain()

- 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: #1694 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `vitest/prefer-to-contain` | no | safe | package `@vitest/eslint-plugin` | [docs](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-contain.md) |
| Oxlint | `vitest/prefer-to-contain` | no | safe | plugin `vitest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-to-contain.html) |
| Biome | `nursery/useExpectToContain` | no | unsafe | group nursery, since 2.6.3 | [docs](https://biomejs.dev/linter/rules/use-expect-to-contain/) |

## Code examples

### Incorrect: the rule reports this

```js
expect(fruits.includes("apple")).toBe(true);
```

```js
expect(fruits.includes("apple")).toEqual(false);
```

```js
expect(fruits.includes("apple")).not.toStrictEqual(true);
```

### Correct: the rule accepts this

```js
expect(fruits).toContain("apple");
expect(fruits).not.toContain("apple");
```

Examples from the Biome documentation.

## Enable it

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

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

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

### Oxlint: `.oxlintrc.json`

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

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useExpectToContain": "error"
      }
    }
  }
}
```

## Related rules

- [jest/prefer-to-contain](https://lintradar.dev/rules/jest/prefer-to-contain.md): Suggest using `toContain()`
- [vitest/prefer-strict-equal](https://lintradar.dev/rules/vitest/prefer-strict-equal.md): Enforce strict equal over equal
- [vitest/prefer-to-have-been-called-times](https://lintradar.dev/rules/vitest/prefer-to-have-been-called-times.md): Suggest using `toHaveBeenCalledTimes()`
- [vitest/prefer-spy-on](https://lintradar.dev/rules/vitest/prefer-spy-on.md): Enforce using `vi.spyOn`
- [vitest/prefer-to-have-length](https://lintradar.dev/rules/vitest/prefer-to-have-length.md): Enforce using toHaveLength()
- [vitest/prefer-importing-vitest-globals](https://lintradar.dev/rules/vitest/prefer-importing-vitest-globals.md): Enforce importing Vitest globals

---

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