# bun:test/prefer-to-contain

> Require `toContain()` instead of comparing the result of `includes()` with a boolean

When `expect(tags.includes("new")).toBe(true)` fails, the message only says that `false` isn't `true`. `expect(tags).toContain("new")` prints the array and the item it looked for.

The rule reports `expect(x.includes(y))` matched against `true` or `false` with `toBe()`, `toEqual()`, or `toStrictEqual()`.

`--fix-suggestions` rewrites the assertion. `--fix` doesn't, because not every object with an `includes()` method works with `toContain()`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"bun:test/prefer-to-contain" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```ts
import { expect, test } from "bun:test";

test("a draft is tagged", () => {
  const tags = getTags(draft);
  expect(tags.includes("draft")).toBe(true);
  expect(tags.includes("published")).toEqual(false);
});
```

Not reported:

{/* good */}
```ts
import { expect, test } from "bun:test";

test("a draft is tagged", () => {
  const tags = getTags(draft);
  expect(tags).toContain("draft");
  expect(tags).not.toContain("published");
});
```

A start index has no equivalent in `toContain()`, so this is allowed:

{/* good */}
```ts
import { expect, test } from "bun:test";

test("the tag is not first", () => {
  expect(getTags(draft).includes("draft", 1)).toBe(true);
});
```
