# prefer-to-contain

Rule `jest/prefer-to-contain`. Suggest using `toContain()`

- 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: #1411 by reach, #1474 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/prefer-to-contain` | no | safe | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/prefer-to-contain.md) |
| Oxlint | `jest/prefer-to-contain` | no | safe | plugin `jest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/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 jest from "eslint-plugin-jest";

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

### Oxlint: `.oxlintrc.json`

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

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useExpectToContain": "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-contain](https://lintradar.dev/rules/vitest/prefer-to-contain.md): Enforce using toContain()
- [jest/prefer-to-have-length](https://lintradar.dev/rules/jest/prefer-to-have-length.md): Suggest using `toHaveLength()`
- [jest/prefer-to-be](https://lintradar.dev/rules/jest/prefer-to-be.md): Suggest using `toBe()` for primitive literals
- [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-contain. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
