Skip to content

Commit fe2d4ad

Browse files
committed
Update CreateKeyPage.expiredToken.test.tsx
1 parent d6852b1 commit fe2d4ad

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

ui/litellm-dashboard/tests/CreateKeyPage.expiredToken.test.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
// @vitest-environment esm
21
import React from "react";
32
import { render, screen, waitFor } from "@testing-library/react";
4-
import "@testing-library/jest-dom";
53
import { vi, describe, it, beforeEach, afterEach, expect } from "vitest";
64

5+
/** ----------------------------
6+
* Hoisted helpers for mocks (required by Vitest)
7+
* --------------------------- */
8+
const { stub, jwtDecodeMock } = vi.hoisted(() => {
9+
const React = require("react");
10+
const stub = (name: string) => () => React.createElement("div", { "data-testid": name });
11+
return {
12+
stub,
13+
jwtDecodeMock: vi.fn(),
14+
};
15+
});
16+
717
/** ----------------------------
818
* Mocks
919
* --------------------------- */
@@ -22,20 +32,16 @@ vi.mock("@/components/networking", () => {
2232
proxyBaseUrl: "https://example.com",
2333
// Called when decoding a valid token
2434
setGlobalLitellmHeaderName: vi.fn(),
25-
Organization: {} as any,
35+
Organization: {},
2636
};
2737
});
2838

2939
// jwt-decode: we’ll swap implementation per test via mockImplementation
30-
const jwtDecodeMock = vi.fn();
3140
vi.mock("jwt-decode", () => ({
3241
jwtDecode: (token: string) => jwtDecodeMock(token),
3342
}));
3443

35-
// Query client provider works fine unmocked
36-
3744
// Super-light stubs for all heavy components so rendering doesn't explode
38-
const stub = (name: string) => () => <div data-testid={name} />;
3945
vi.mock("@/components/navbar", () => ({ default: stub("navbar") }));
4046
vi.mock("@/components/user_dashboard", () => ({ default: stub("user-dashboard") }));
4147
vi.mock("@/components/templates/model_dashboard", () => ({ default: stub("model-dashboard") }));
@@ -70,9 +76,12 @@ vi.mock("@/components/common_components/fetch_teams", () => ({ fetchTeams: vi.fn
7076
vi.mock("@/components/ui/ui-loading-spinner", () => ({
7177
UiLoadingSpinner: stub("spinner"),
7278
}));
73-
vi.mock("@/contexts/ThemeContext", () => ({
74-
ThemeProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
75-
}));
79+
vi.mock("@/contexts/ThemeContext", () => {
80+
const React = require("react");
81+
return {
82+
ThemeProvider: ({ children }: any) => React.createElement(React.Fragment, null, children),
83+
};
84+
});
7685
vi.mock("@/lib/cva.config", () => ({
7786
cx: (...args: string[]) => args.join(" "),
7887
}));

0 commit comments

Comments
 (0)