From 98de76abf48031e59fd8bc19210dc39f95946c3e Mon Sep 17 00:00:00 2001 From: Mrinal Chanshetty Date: Mon, 2 Nov 2026 19:34:08 -0800 Subject: [PATCH] test(ui): assert unexpected user-creation requests --- .../components/CreateUserButton.integration.test.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ui/litellm-dashboard/src/components/CreateUserButton.integration.test.tsx b/ui/litellm-dashboard/src/components/CreateUserButton.integration.test.tsx index 24059e21ee6..e89211596f3 100644 --- a/ui/litellm-dashboard/src/components/CreateUserButton.integration.test.tsx +++ b/ui/litellm-dashboard/src/components/CreateUserButton.integration.test.tsx @@ -5,8 +5,12 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { CreateUserButton } from "./CreateUserButton"; const createUser = vi.fn<(body: Record) => Response>(); +const unexpectedRequest = vi.fn((path: string) => + Response.json({ error: `Unexpected request ${path}` }, { status: 500 }), +); beforeEach(() => { + unexpectedRequest.mockClear(); createUser.mockReset(); createUser.mockImplementation((body) => Response.json({ user_id: body.user_id ?? "generated-id" })); vi.stubGlobal( @@ -17,12 +21,15 @@ beforeEach(() => { if (path === "/models") return Response.json({ data: [] }); if (path === "/sso/get/ui_settings") return Response.json({ SSO_ENABLED: true }); if (path === "/v2/team/list") return Response.json({ teams: [], total: 0, total_pages: 0 }); - throw new Error(`Unexpected request ${path}`); + return unexpectedRequest(path); }), ); }); -afterEach(() => vi.unstubAllGlobals()); +afterEach(() => { + vi.unstubAllGlobals(); + expect(unexpectedRequest).not.toHaveBeenCalled(); +}); const renderForm = (isEmbedded: boolean, onUserCreated = vi.fn()) => { const client = new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 0 } } });