From 8d139fe706d6e90c510fc2fba5a9c32e3c7cd572 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 15 Aug 2026 01:38:18 +0000 Subject: [PATCH] test(ui): await handleSearch completion in SearchToolTester tests Wait for the async search operation to fully settle before ending tests that fire handleSearch without checking downstream results. The finally block's setIsLoading(false) was racing with test-file JSDOM teardown, leaking a 'window is not defined' error from React's requestUpdateLane after the environment was gone and failing the whole UI Unit Tests job. Co-authored-by: Krrish Dholakia --- .../search-tools/_components/SearchToolTester.test.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/litellm-dashboard/src/app/(dashboard)/search-tools/_components/SearchToolTester.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/search-tools/_components/SearchToolTester.test.tsx index fd944120624..09649e48953 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/search-tools/_components/SearchToolTester.test.tsx +++ b/ui/litellm-dashboard/src/app/(dashboard)/search-tools/_components/SearchToolTester.test.tsx @@ -93,6 +93,7 @@ describe("SearchToolTester", () => { const searchButton = screen.getByRole("button", { name: /search/i }); await user.click(searchButton); expect(networking.searchToolQueryCall).toHaveBeenCalledWith("test-token", "test-search-tool", "test query"); + await waitFor(() => expect(searchButton).not.toBeDisabled()); }); it("should call searchToolQueryCall when Enter is pressed in input", async () => { @@ -101,6 +102,7 @@ describe("SearchToolTester", () => { const input = screen.getByPlaceholderText("Enter your search query..."); await user.type(input, "test query{Enter}"); expect(networking.searchToolQueryCall).toHaveBeenCalledWith("test-token", "test-search-tool", "test query"); + await waitFor(() => expect(input).not.toBeDisabled()); }); it("should not call searchToolQueryCall when Shift+Enter is pressed", async () => { @@ -123,6 +125,7 @@ describe("SearchToolTester", () => { const searchButton = screen.getByRole("button", { name: /search/i }); await user.click(searchButton); expect(screen.getByText("Searching...")).toBeInTheDocument(); + await waitFor(() => expect(screen.queryByText("Searching...")).not.toBeInTheDocument()); }); it("should display search results after successful search", async () => { @@ -407,6 +410,7 @@ describe("SearchToolTester", () => { await user.click(searchButton); expect(input).toBeDisabled(); expect(searchButton).toBeDisabled(); + await waitFor(() => expect(input).not.toBeDisabled()); }); it("should display result links that open in new tab", async () => {