1- // @vitest -environment esm
21import React from "react" ;
32import { render , screen , waitFor } from "@testing-library/react" ;
4- import "@testing-library/jest-dom" ;
53import { 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 ( ) ;
3140vi . 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 } /> ;
3945vi . mock ( "@/components/navbar" , ( ) => ( { default : stub ( "navbar" ) } ) ) ;
4046vi . mock ( "@/components/user_dashboard" , ( ) => ( { default : stub ( "user-dashboard" ) } ) ) ;
4147vi . mock ( "@/components/templates/model_dashboard" , ( ) => ( { default : stub ( "model-dashboard" ) } ) ) ;
@@ -70,9 +76,12 @@ vi.mock("@/components/common_components/fetch_teams", () => ({ fetchTeams: vi.fn
7076vi . 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+ } ) ;
7685vi . mock ( "@/lib/cva.config" , ( ) => ( {
7786 cx : ( ...args : string [ ] ) => args . join ( " " ) ,
7887} ) ) ;
0 commit comments