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) }),
);

Explanation

Others: expect.arrayContaining, expect.stringMatching, expect.anything(). Tests stay precise without being brittle.

Further reading

Problem with a question

Testing · Middle · question 73

Test yourself

Take the Testing · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz