> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-to-contain

[Added in v0.5.2](https://github.com/web-infra-dev/rslint/releases/tag/v0.5.2)
## Configuration

| Preset                     | Configured Value |
| -------------------------- | ---------------- |
| ✅ jestPlugin.configs.all   | `"error"`        |
| ✅ jestPlugin.configs.style | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, jestPlugin } from '@rslint/core';

export default defineConfig([
  jestPlugin.configs.recommended,
  {
    rules: {
      'jest/prefer-to-contain': 'error',
    },
  },
]);
```

## Rule Details

In order to have a better failure message, `toContain()` should be used upon asserting expectations on an array containing an object.

This rule triggers a warning if `toBe()`, `toEqual()` or `toStrictEqual()` is used to assert object inclusion in an array.

Examples of **incorrect** code for this rule:

```js
expect(a.includes(b)).toBe(true);
expect(a.includes(b)).not.toBe(true);
expect(a.includes(b)).toBe(false);
expect(a.includes(b)).toEqual(true);
expect(a.includes(b)).toStrictEqual(true);
```

Examples of **correct** code for this rule:

```js
expect(a).toContain(b);
expect(a).not.toContain(b);
```

## Original Documentation

- [eslint-plugin-jest: prefer-to-contain](https://github.com/jest-community/eslint-plugin-jest/blob/v29.16.0/docs/rules/prefer-to-contain.md)
- [Source code](https://github.com/jest-community/eslint-plugin-jest/blob/v29.16.0/src/rules/prefer-to-contain.ts)
