Challenge: partial object matches - a few approaches

When writing tests you will often check that functions that return complex and nested objects are of a certain shape - but you normally just want to check one or two fields. A test that is only checking the values that are relevant is often easier to read, easier to maintain, and when it fails is much easier to debug.

This testing challenge is set up to simulate that. We basically want to show how to assert that a function's return value contains a couple of key/values... but we want to ignore the rest of the object (as it isn't relevant for our test).

There are a few approaches, and knowing how to use each one is important to help you write clean tests that are easy to read.

i
Challenge Mode: This lesson is actually a challenge - you are given a half working test and have to figure out how to get it working correctly.

You can use our courses to learn how to solve this challenge - there are courses on everything from basic Jest/Vitest fundamentals, down to how to test frontend code (using React Testing Library).

Loading full lesson content & code...

Ready to try running tests for this lesson?