From 3c3b162aab721b25b2839c5e6185794cec6992c2 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Sat, 6 Jun 2026 10:27:41 -0700 Subject: [PATCH] Fix sports.test.tsx timeout: mock SportIcon to eliminate async image-error state updates SportIcon renders elements whose onError handler calls setFailed(true), scheduling state updates asynchronously outside React act() in jsdom. With multiple icons on the Sports page this caused the synchronous render test to hit the 5000ms Vitest timeout intermittently. Mock SportIcon in the test using resolveSportIconUrl() so the mock stays in sync with the real URL resolution logic if it ever changes. Co-Authored-By: Claude Sonnet 4.6 --- app/routes/__tests__/sports.test.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/routes/__tests__/sports.test.tsx b/app/routes/__tests__/sports.test.tsx index 84d5f91..95e2599 100644 --- a/app/routes/__tests__/sports.test.tsx +++ b/app/routes/__tests__/sports.test.tsx @@ -6,6 +6,16 @@ vi.mock("~/models/sport", () => ({ findPublicSportsWithCurrentSeasons: vi.fn(), })); +vi.mock("~/components/SportIcon", async () => { + const { resolveSportIconUrl } = await import("~/lib/sport-icon-url"); + return { + SportIcon: ({ sportName, iconUrl }: { sportName: string; iconUrl?: string | null }) => { + const src = resolveSportIconUrl(iconUrl); + return src ? {sportName} : null; + }, + }; +}); + import Sports, { loader } from "../sports"; import { findPublicSportsWithCurrentSeasons } from "~/models/sport"; import type { PublicSportWithCurrentSeasons } from "~/models/sport";