TypeScript · testing
prefer-whole-object-assertion
eslint:prefer-whole-object-assertion Collapse consecutive assertions on one object into a whole-object assertion so related mismatches are reported together.
- Default
- error
- Fix
- safe
- Languages
- typescript
Why
One whole-object assertion presents related expectations together and produces a complete structural diff.
Fix
Replace consecutive member assertions with one `toMatchObject` assertion.
Before / after
Executed by this rule’s unit tests.
Before
Do not split one object across assertions
expect(user.id).toBe(1);
expect(user.name).toBe('Ada'); Autofix output
expect(user).toMatchObject({ id: 1, name: 'Ada' });
After
Assert the object once
expect(user).toMatchObject({ id: 1, name: 'Ada' }); Message IDs
assertArrayOncecombineAssertionsFormerly: strict-test-assertions