# jest/prefer-equality-matcher

> Require `toBe` or `toEqual` instead of comparing with `===` inside `expect`

`expect(a === b).toBe(true)` compares the values before `expect` sees them. When the test fails, the output only says that `false` is not `true`. It doesn't show the two values.

The rule reports `===` and `!==` inside `expect` when the result is compared with `true` or `false` using `toBe`, `toEqual` or `toStrictEqual`. `==` and `!=` aren't reported.

`--fix-suggestions` rewrites the assertion with `toBe`. Your editor also offers `toEqual` and `toStrictEqual`.

{/* 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]
"jest/prefer-equality-matcher" = "error" # or "warn"
```

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

## Examples

Reported:

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

test("the session belongs to the user", () => {
  expect(session.userId === user.id).toBe(true);
  expect(user.role !== "admin").toBe(true);
});
```

Not reported:

{/* good */}
```ts
import { expect, test } from "@jest/globals";

test("the session belongs to the user", () => {
  expect(session.userId).toBe(user.id);
  expect(user.role).not.toBe("admin");
});
```

{/* good */}
```ts
import { expect, test } from "@jest/globals";

test("the port matches the string in the config", () => {
  expect(server.port == config.port).toBe(true);
});
```
