> 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.9.3](https://github.com/web-infra-dev/rslint/releases/tag/v0.9.3)
## Configuration

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


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

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

## Rule Details

This rule requires `toContain()` when an equality assertion checks the boolean result of a single-argument `includes()` call. The dedicated matcher states the intended containment check directly and produces a more useful failure message.

The rule recognizes `toBe()`, `toEqual()` and `toStrictEqual()`, including negated forms, and preserves the assertion's meaning when deciding whether the replacement needs `.not`. It recognizes Rstest globals, imports and aliases, namespace and `require` bindings, `rstack/test`, `import.meta.rstest`, `expect.soft()`, Playwright's ordinary value assertions, and the `expect` supplied by a [test context](https://rstest.rs/api/runtime-api/test-api/test#testcontext).

Polling assertions, promise modifiers, browser-only `expect.element()` assertions, Chai-style equality assertions with `.deep`, assertion chains that continue after the equality matcher, dynamic accessors and explicit `NaN` items are left unchanged. A regular-expression item is also excluded unless the receiver is visibly an array literal. This avoids suggesting a non-equivalent matcher for a possibly string-valued receiver because native string `includes()` rejects regular expressions. Rstest's array `toContain()` also does not match `Array.prototype.includes()` for `NaN`.

## Incorrect

```ts
expect(flavors.includes('lime')).toBe(true);
expect(roles.includes('admin')).not.toEqual(false);
expect(tags.includes('deprecated')).toStrictEqual(false);
```

## Correct

```ts
expect(flavors).toContain('lime');
expect(roles).toContain('admin');
expect(tags).not.toContain('deprecated');
```

## Autofix

The autofix moves the `includes()` receiver and item into `expect(receiver).toContain(item)`, removes explicit type arguments from the `expect()` factory and equality matcher, then adds or removes `.not` to preserve the boolean assertion. Quoted and template-literal matcher accessors retain their delimiters. If the moved item may have side effects, `expect()` has a custom message argument, or an edited expression or removed type argument list contains a comment, the rule reports the assertion without a fix.
