test(ui): add getCookie to cookieUtils mock in user_dashboard test#25719
test(ui): add getCookie to cookieUtils mock in user_dashboard test#25719yuneng-berri merged 1 commit intomainfrom
Conversation
user_dashboard.tsx imports getCookie from @/utils/cookieUtils, but the vi.mock factory in user_dashboard.test.tsx only exports clearTokenCookies. Vitest throws `No "getCookie" export is defined on the "@/utils/cookieUtils" mock`, breaking all three beforeunload-listener tests. Add getCookie to the mock factory so it matches the current imports.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes three failing tests in Confidence Score: 5/5Safe to merge — single-line test fix that correctly restores a missing mock export without weakening any assertions. The change adds one missing entry to a Vitest mock factory to match the component's actual imports. No production code is touched, no assertions are weakened, and the mock value ("fake-jwt-token") is consistent with the existing document.cookie setup in the same test file. No P0/P1 findings. No files require special attention.
|
| Filename | Overview |
|---|---|
| ui/litellm-dashboard/src/components/user_dashboard.test.tsx | Adds getCookie: vi.fn().mockReturnValue("fake-jwt-token") to the cookieUtils mock factory to match the component's actual imports; restores three previously failing tests. |
Sequence Diagram
sequenceDiagram
participant Test as Test (Vitest)
participant Mock as vi.mock(@/utils/cookieUtils)
participant Comp as UserDashboard
participant Window as window
Test->>Mock: resolve module mock
Mock-->>Comp: clearTokenCookies, getCookie("fake-jwt-token")
Test->>Comp: render()
Comp->>Mock: getCookie("token") → "fake-jwt-token"
Comp->>Window: addEventListener("beforeunload", handler)
Test->>Test: assert exactly 1 beforeunload listener ✓
Test->>Comp: rerender(new props)
Test->>Test: assert 0 new beforeunload listeners ✓
Test->>Comp: unmount()
Comp->>Window: removeEventListener("beforeunload", handler)
Test->>Test: assert exactly 1 remove call ✓
Reviews (1): Last reviewed commit: "test(ui): add getCookie to cookieUtils m..." | Re-trigger Greptile
Summary
Fixes three failing tests in
src/components/user_dashboard.test.tsx:registers exactly one beforeunload listener on mountdoes not add duplicate listeners on re-renderremoves the beforeunload listener on unmountuser_dashboard.tsximportsgetCookiefrom@/utils/cookieUtils, but thevi.mockfactory in the test only exportedclearTokenCookies. Vitest's strict mock factory then throws:```
Error: [vitest] No "getCookie" export is defined on the "@/utils/cookieUtils" mock.
```
...causing the source file to error during render and all three tests to fail.
Added
getCookie: vi.fn().mockReturnValue("fake-jwt-token")to the mock factory so it matches the current set of imports fromcookieUtils.Test plan
vitest run src/components/user_dashboard.test.tsx— 3/3 passing locally