test(ui): settle the in-flight search before the loading tests end

Both loading tests mock searchToolQueryCall as a promise that resolves on a
timer, assert the loading affordance, then return with that promise still in
flight. When the worker outlives the file's jsdom environment, the component's
setIsLoading(false) runs against a torn-down window, and React reports
"ReferenceError: window is not defined" as an unhandled rejection. Vitest counts
that as an error, so ui-unit-tests fails the job while reporting every one of
its 7351 tests as passed.

Awaiting the settled state keeps both assertions and leaves nothing pending at
teardown.
This commit is contained in:
Yuneng Jiang 2026-08-17 15:41:31 -07:00
parent 67635d832e
commit 3cc16de0d2
No known key found for this signature in database

View file

@ -123,6 +123,8 @@ describe("SearchToolTester", () => {
const searchButton = screen.getByRole("button", { name: /search/i });
await user.click(searchButton);
expect(screen.getByText("Searching...")).toBeInTheDocument();
expect(await screen.findByText("Test Result 1")).toBeInTheDocument();
});
it("should display search results after successful search", async () => {
@ -407,6 +409,8 @@ describe("SearchToolTester", () => {
await user.click(searchButton);
expect(input).toBeDisabled();
expect(searchButton).toBeDisabled();
await waitFor(() => expect(searchButton).toBeEnabled());
});
it("should display result links that open in new tab", async () => {