Testing · Middle · Question 73 of 75
What do asymmetric matchers like expect.objectContaining give you?
expect(track).toHaveBeenCalledWith(
"purchase",
expect.objectContaining({ total: 30, id: expect.any(String) }),
);- ✓Correct answer: They check only the parts that matter (some keys, a type) and ignore the rest, like generated ids and timestamps
- 2They make the comparison case-insensitive
- 3They compare objects by reference
Explanation
Others: expect.arrayContaining, expect.stringMatching, expect.anything(). Tests stay precise without being brittle.