import { QueryClientProvider } from "@tanstack/react-query"; import { renderHook, waitFor } from "@testing-library/react"; import type { ReactNode } from "react"; import { afterEach, describe, expect, it, vi } from "vitest"; import { upliftsApi } from "@/domain/uplifts/api/uplifts-api"; import { useUpliftsQueue } from "@/domain/uplifts/use-cases/use-uplifts-queue"; import { createAppQueryClient } from "@/lib/query/query-client"; const toastMocks = vi.hoisted(() => ({ error: vi.fn() })); vi.mock("react-toastify", () => ({ toast: { error: toastMocks.error, success: vi.fn() }, })); afterEach(() => { vi.restoreAllMocks(); toastMocks.error.mockReset(); }); describe("useUpliftsQueue", () => { it("does not show the global error toast, since the approvals page reports the failure inline", async () => { vi.spyOn(upliftsApi, "list").mockRejectedValue(new Error("Failed to load uplift queue")); // The real app query client runs the QueryCache's global onError handler, which // toasts unless the query opts out. const queryClient = createAppQueryClient(); queryClient.setDefaultOptions({ queries: { retry: false } }); const { result } = renderHook( () => useUpliftsQueue({ status: "Rejected", page: 1, pageSize: 25 }), { wrapper: ({ children }: { children: ReactNode }) => ( {children} ), }, ); await waitFor(() => expect(result.current.error).toBeInstanceOf(Error)); expect(toastMocks.error).not.toHaveBeenCalled(); }); });