Skip to content

test(ui): add getCookie to cookieUtils mock in user_dashboard test#25719

Merged
yuneng-berri merged 1 commit intomainfrom
litellm_fix-ui-unit-tests-get-cookie
Apr 14, 2026
Merged

test(ui): add getCookie to cookieUtils mock in user_dashboard test#25719
yuneng-berri merged 1 commit intomainfrom
litellm_fix-ui-unit-tests-get-cookie

Conversation

@ryan-crabbe-berri
Copy link
Copy Markdown
Collaborator

Summary

Fixes three failing tests in src/components/user_dashboard.test.tsx:

  • registers exactly one beforeunload listener on mount
  • does not add duplicate listeners on re-render
  • removes the beforeunload listener on unmount

user_dashboard.tsx imports getCookie from @/utils/cookieUtils, but the vi.mock factory in the test only exported clearTokenCookies. 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 from cookieUtils.

Test plan

  • vitest run src/components/user_dashboard.test.tsx — 3/3 passing locally

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.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 14, 2026 10:19pm

Request Review

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq bot commented Apr 14, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing litellm_fix-ui-unit-tests-get-cookie (bdaaa5c) with main (43efe76)

Open in CodSpeed

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR fixes three failing tests in user_dashboard.test.tsx by adding the missing getCookie export to the @/utils/cookieUtils Vitest mock factory. The component imports both clearTokenCookies and getCookie from that module, but the mock only exposed clearTokenCookies, causing Vitest's strict module mock to throw at render time and fail all three beforeunload listener tests.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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 ✓
Loading

Reviews (1): Last reviewed commit: "test(ui): add getCookie to cookieUtils m..." | Re-trigger Greptile

@yuneng-berri yuneng-berri enabled auto-merge April 14, 2026 22:31
@yuneng-berri yuneng-berri self-requested a review April 14, 2026 22:31
@yuneng-berri yuneng-berri merged commit 7b36cfc into main Apr 14, 2026
97 of 106 checks passed
@yuneng-berri yuneng-berri deleted the litellm_fix-ui-unit-tests-get-cookie branch April 14, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants