# vitest/prefer-strict-equal

> Require `toStrictEqual()` instead of `toEqual()`

`toEqual()` skips properties that are `undefined`, treats a hole in an array like `undefined`, and doesn't compare the classes of the two objects. So `expect({ name: "Ada", email: undefined }).toEqual({ name: "Ada" })` passes. `toStrictEqual()` checks all three, and that test fails.

`--fix-suggestions` renames the matcher. `--fix` doesn't, because a test that passes with `toEqual()` can fail with `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]
"vitest/prefer-strict-equal" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad */}
```ts
import { expect, test } from "vitest";

test("creates a user", () => {
  expect(createUser("Ada")).toEqual({ name: "Ada" });
});
```

Not reported:

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

test("creates a user", () => {
  expect(createUser("Ada")).toStrictEqual({ name: "Ada" });
});
```

## When not to use it

If your code builds objects with optional properties set to `undefined`, or you compare class instances with plain objects on purpose, `toEqual()` is the matcher you want.
