Skip to content

prefer-whole-object-assertion

Collapse consecutive assertions on one object into a whole-object assertion so related mismatches are reported together.

Why

One whole-object assertion presents related expectations together and produces a complete structural diff.

Fix

Consider one toMatchObject assertion for ordinary data objects. Preserve missing-property checks, identity, and getter or proxy behavior when deciding whether to combine assertions.

Examples

Before — flagged Consider grouping related data properties
src/user.test.ts
expect(user.id).toBe(1);
expect(user.name).toBe("Ada");
After — preferred Assert the object once
src/user.test.ts
expect(user).toMatchObject({ id: 1, name: "Ada" });

Formerly: strict-test-assertions