Problem Brief
Build a search autocomplete bar that debounces keystrokes (300ms), filters results case-insensitively, highlights matches, and handles empty states.
Requirements
- Keep `[data-testid="search-input"]` and `[data-testid="results-list"]`.
- Debounce filtering by 300ms so rapid keystrokes only trigger one filter run.
- Display matching `<li class="result-item">` rows (or a `"No results found"` message inside `[data-testid="empty-state"]`).
- Increment `[data-testid="search-calls"]` count only when a debounced filter executes.
Progressive Hints (2)
- Clear the previous `setTimeout` handle on every `input` event before scheduling a new 300ms timer.
- Trim and lowercase the query before calling `.includes()`.
Reference Solution
Stuck? Load the verified reference code into your editor.
Automated Test Suite
5 Test Cases Ready- Does not execute synchronously on immediate keystroke (debounced)search-calls remains 0 immediately after firing input event
- Collapses rapid typing into a single debounced call after 350msMultiple fast input events yield search-calls = 1 after debounce window
- Case-insensitive filtering matches multiple catalog itemsTyping "PRO" matches iPhone 16 Pro and AirPods Pro
- Shows empty state when query matches nothingReveals [data-testid="empty-state"] with "No results found"
- Clearing input hides empty state and empties resultsEmpty query resets list and hides empty state banner
Live Sandboxed Previewiframe sandbox