From fe2d4addfa7e63af84a34df2a732c469c94db55c Mon Sep 17 00:00:00 2001 From: Achintya Rajan Date: Wed, 8 Oct 2025 14:10:09 -0700 Subject: [PATCH] Update CreateKeyPage.expiredToken.test.tsx --- .../tests/CreateKeyPage.expiredToken.test.tsx | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ui/litellm-dashboard/tests/CreateKeyPage.expiredToken.test.tsx b/ui/litellm-dashboard/tests/CreateKeyPage.expiredToken.test.tsx index db2d131584..93e15312f6 100644 --- a/ui/litellm-dashboard/tests/CreateKeyPage.expiredToken.test.tsx +++ b/ui/litellm-dashboard/tests/CreateKeyPage.expiredToken.test.tsx @@ -1,9 +1,19 @@ -// @vitest-environment esm import React from "react"; import { render, screen, waitFor } from "@testing-library/react"; -import "@testing-library/jest-dom"; import { vi, describe, it, beforeEach, afterEach, expect } from "vitest"; +/** ---------------------------- + * Hoisted helpers for mocks (required by Vitest) + * --------------------------- */ +const { stub, jwtDecodeMock } = vi.hoisted(() => { + const React = require("react"); + const stub = (name: string) => () => React.createElement("div", { "data-testid": name }); + return { + stub, + jwtDecodeMock: vi.fn(), + }; +}); + /** ---------------------------- * Mocks * --------------------------- */ @@ -22,20 +32,16 @@ vi.mock("@/components/networking", () => { proxyBaseUrl: "https://example.com", // Called when decoding a valid token setGlobalLitellmHeaderName: vi.fn(), - Organization: {} as any, + Organization: {}, }; }); // jwt-decode: we’ll swap implementation per test via mockImplementation -const jwtDecodeMock = vi.fn(); vi.mock("jwt-decode", () => ({ jwtDecode: (token: string) => jwtDecodeMock(token), })); -// Query client provider works fine unmocked - // Super-light stubs for all heavy components so rendering doesn't explode -const stub = (name: string) => () =>
; vi.mock("@/components/navbar", () => ({ default: stub("navbar") })); vi.mock("@/components/user_dashboard", () => ({ default: stub("user-dashboard") })); vi.mock("@/components/templates/model_dashboard", () => ({ default: stub("model-dashboard") })); @@ -70,9 +76,12 @@ vi.mock("@/components/common_components/fetch_teams", () => ({ fetchTeams: vi.fn vi.mock("@/components/ui/ui-loading-spinner", () => ({ UiLoadingSpinner: stub("spinner"), })); -vi.mock("@/contexts/ThemeContext", () => ({ - ThemeProvider: ({ children }: { children: React.ReactNode }) => <>{children}, -})); +vi.mock("@/contexts/ThemeContext", () => { + const React = require("react"); + return { + ThemeProvider: ({ children }: any) => React.createElement(React.Fragment, null, children), + }; +}); vi.mock("@/lib/cva.config", () => ({ cx: (...args: string[]) => args.join(" "), }));