Skip to content

Commit dc70cdb

Browse files
committed
fix: flaky focus test on Windows by waiting for debounce timer
The test 'does not grab focus when follow-up question presented' was failing intermittently on Windows because the 50ms debounced focus effect in ChatView could fire after mockFocus.mockClear() was called. Added explicit delays (100ms) after state changes to ensure the debounced effect completes before clearing mocks or making assertions. This eliminates the race condition that caused the test to pass on Ubuntu but fail on Windows.
1 parent 703a296 commit dc70cdb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

webview-ui/src/components/chat/__tests__/ChatView.spec.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,11 @@ describe("ChatView - Focus Grabbing Tests", () => {
468468
expect(getByTestId("chat-textarea")).toBeInTheDocument()
469469
})
470470

471-
// Clear any initial calls after state has settled
471+
// Wait for the debounced focus effect (50ms) to complete.
472+
// This prevents race conditions where the debounce timer fires after mockClear.
473+
await new Promise((resolve) => setTimeout(resolve, 100))
474+
475+
// Clear any initial calls after state has fully settled (including debounced effects)
472476
mockFocus.mockClear()
473477

474478
// Add follow-up question
@@ -494,6 +498,9 @@ describe("ChatView - Focus Grabbing Tests", () => {
494498
expect(getByTestId("chat-textarea")).toBeInTheDocument()
495499
})
496500

501+
// Wait for any debounced effects to fire
502+
await new Promise((resolve) => setTimeout(resolve, 100))
503+
497504
// Should not grab focus for follow-up questions
498505
expect(mockFocus).not.toHaveBeenCalled()
499506
})

0 commit comments

Comments
 (0)