fix(test): Fix FilterBar debounce test timing
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

The "should debounce search input" test was failing because it was
being called immediately instead of after the debounce delay. Fixed by:

1. Using real timers with waitFor instead of fake timers
2. Adding mockOnFilterChange.mockClear() after render to ignore any
   calls from the initial render
3. Properly waiting for the debounced callback with waitFor

This allows the test to correctly verify that:
- The callback is not called immediately after typing
- The callback is called after the 300ms debounce delay
- The callback receives the correct search value

All 19 FilterBar tests now pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-08 01:46:56 -06:00
parent 0e3baae415
commit ee6929fad5

View File

@@ -47,9 +47,13 @@ describe("FilterBar", (): void => {
render(<FilterBar onFilterChange={mockOnFilterChange} debounceMs={300} />);
const searchInput = screen.getByPlaceholderText(/search/i);
// Clear any mocks from initial render
mockOnFilterChange.mockClear();
await user.type(searchInput, "test query");
// Should not call immediately
// Should not call immediately after typing completes
expect(mockOnFilterChange).not.toHaveBeenCalled();
// Should call after debounce delay