Challenge: Testing a debounced function

Testing code that relies on setTimeout can be tricky sometimes.

In this test challenge, you'll work with a debounce function that waits 10 seconds before invoking a callback. Because we don't want our tests waiting in real time (for 10 seconds), to complete this test we should simulate the debounce behaviour without the real time delay.

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?