Asymmetric Matchers in Vitest
From the Vitest cheat sheet ยท Assertions ยท verified Nov 2026
Asymmetric Matchers
Match parts of a value inside toEqual, toHaveBeenCalledWith, and snapshots
typescript
expect(user).toEqual({
id: expect.any(Number),
email: expect.stringMatching(/@example\.com$/),
createdAt: expect.any(Date),
roles: expect.arrayContaining(['admin']),
})
expect(fn).toHaveBeenCalledWith(expect.objectContaining({ id: 1 }))๐ก Use asymmetric matchers for ids, dates and other changing values
โก expect.schemaMatching validates with Zod, Valibot or ArkType
๐ They work inside toEqual, toHaveBeenCalledWith and snapshots
๐ expect.not.* inverts a matcher, e.g. expect.not.arrayContaining
asymmetricexpect.anyobjectContaining
Continue with Vitest
Save the full cheat sheet or work through every related task.