The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
build(ui): gate dashboard test assertions with testing-library and jest-dom
Yuneng Jiang41d6dbb50c16
diff --git a/ui/litellm-dashboard/CLAUDE.md b/ui/litellm-dashboard/CLAUDE.mdindex 701b37ec6aa..9640784c21d 100644--- a/ui/litellm-dashboard/CLAUDE.md+++ b/ui/litellm-dashboard/CLAUDE.md@@ -9,3 +9,13 @@ Tests come in three tiers, named by the standard definitions. `Foo.test.tsx` isWhen a component holds logic worth asserting, extract the logic and unit-test it there rather than driving it through a render. `CreateMCPServer` is the worked example: its payload building lives in `createServerPayload.ts` with 46 unit tests that run in single-digit milliseconds, while `CreateMCPServer.integration.test.tsx` keeps only the cases that prove a form field reaches the right payload key. A test that renders a whole modal to assert the shape of one object belongs in the first category, not the secondMost of the suite predates this split and is not yet classified, so an unsuffixed `*.test.tsx` is not evidence that a file is really a unit test. Classify what you touch++Assert something the user could perceive, and assert it precisely enough that the test fails when the behaviour breaks. `eslint-plugin-testing-library` and `eslint-plugin-jest-dom` enforce the mechanical part of that. Two of the enabled rules exist because the failure they catch is silent rather than cosmetic: `await-async-queries` catches an unawaited `findBy*`, whose returned Promise is always truthy and makes the whole assertion vacuous, and `no-wait-for-side-effects` catches work inside a `waitFor` callback, which is retried on every poll. Prefer `findBy*` over `waitFor` wrapped around `getBy*`, and keep a `waitFor` callback to a single assertion++Do not trust `eslint --fix` for these two plugins. Fixing the suite in bulk produced seven distinct kinds of broken output. Four fail loudly: `no-wait-for-side-effects` and `no-wait-for-multiple-assertions` hoist a statement out of the `waitFor` callback while leaving the `const` it reads inside, `prefer-enabled-disabled` drops a closing paren when the subject carries a type assertion, `prefer-presence-queries` swaps in a query it never destructures, and `prefer-in-document` collapses `getAllBy*` to `getBy*` on a value still indexed as an array. Two fail quietly, which is worse: `prefer-checked` swaps the `checked` attribute for the `.checked` property, and antd radios set one without the other, and `prefer-to-have-text-content` wraps arbitrary strings in `new RegExp()` without escaping, so `toContain("100K+ requests")` becomes a pattern meaning "100 followed by one-or-more K". That last one compiles, lints clean, and keeps passing while no longer asserting what it says. Pass a plain string to `toHaveTextContent`, which is already a substring match. Run the fixer on a handful of files at a time and read the diff++`jest-dom/prefer-to-have-value` stays off because its fixer is wrong here, not merely noisy. It matches any attribute whose name contains "value", so it rewrites `toHaveAttribute("aria-valuenow", n)` into `toHaveValue(n)`, and jest-dom's `toHaveValue` only supports form controls, so the assertion fails on the `role="meter"` elements the dashboard renders. Assert ARIA value attributes with `toHaveAttribute`++A test may reach for a component library's own CSS class only when that library exposes no role, label, title or ARIA state to query instead, and then the line carries a suppression naming the rule and the reason. Check first: antd icons render as `role="img"` with an `aria-label`, and antd `Form.Item` associates its label with the control, so both are reachable accessibly. When a label does not resolve, suspect the control rather than the test, since a custom wrapper that destructures props without spreading them drops the `id` antd injects and leaves the rendered label pointing at nothing++Rules beyond the enabled set were measured against the whole suite and left off rather than recorded in a budget file, because a ceiling that permits a violation anywhere is worse than an honest gap. `no-node-access` and `no-container` are the ones worth revisiting first, since they catch the DOM archaeology the rules above only discourage. `prefer-implicit-assert` and `prefer-explicit-assert` contradict each other, so neither is enableddiff --git a/ui/litellm-dashboard/eslint.config.mjs b/ui/litellm-dashboard/eslint.config.mjsindex 73d1ee439b4..35603123736 100644--- a/ui/litellm-dashboard/eslint.config.mjs+++ b/ui/litellm-dashboard/eslint.config.mjs@@ -3,6 +3,8 @@ import tseslint from "typescript-eslint";import nextCoreWebVitals from "eslint-config-next/core-web-vitals";import prettier from "eslint-config-prettier/flat";import unusedImports from "eslint-plugin-unused-imports";+import testingLibrary from "eslint-plugin-testing-library";+import jestDom from "eslint-plugin-jest-dom";import local from "./scripts/eslint-rules/index.mjs";const eslintConfig = [@@ -86,8 +88,23 @@ const eslintConfig = [},{files: ["src/**/*.test.{ts,tsx}", "tests/**/*.{ts,tsx}"],+ plugins: { "testing-library": testingLibrary, "jest-dom": jestDom },rules: {"local/no-antd-class-selectors": "error",+ "testing-library/await-async-queries": "error",+ "testing-library/no-wait-for-multiple-assertions": "error",+ "testing-library/no-wait-for-side-effects": "error",+ "testing-library/prefer-find-by": "error",+ "testing-library/prefer-presence-queries": "error",+ "jest-dom/prefer-checked": "error",+ "jest-dom/prefer-empty": "error",+ "jest-dom/prefer-enabled-disabled": "error",+ "jest-dom/prefer-focus": "error",+ "jest-dom/prefer-in-document": "error",+ "jest-dom/prefer-to-have-attribute": "error",+ "jest-dom/prefer-to-have-class": "error",+ "jest-dom/prefer-to-have-style": "error",+ "jest-dom/prefer-to-have-text-content": "error",},},];diff --git a/ui/litellm-dashboard/package-lock.json b/ui/litellm-dashboard/package-lock.jsonindex b36b07631e3..92fc37c959c 100644--- a/ui/litellm-dashboard/package-lock.json+++ b/ui/litellm-dashboard/package-lock.json@@ -64,6 +64,8 @@"eslint": "9.39.2","eslint-config-next": "16.2.11","eslint-config-prettier": "10.1.8",+ "eslint-plugin-jest-dom": "5.10.1",+ "eslint-plugin-testing-library": "7.16.2","eslint-plugin-unused-imports": "4.3.0","jsdom": "27.4.0","knip": "5.83.1",@@ -6886,6 +6888,30 @@"semver": "bin/semver.js"}},+ "node_modules/eslint-plugin-jest-dom": {+ "version": "5.10.1",+ "resolved": "https://registry.npmjs.org/eslint-plugin-jest-dom/-/eslint-plugin-jest-dom-5.10.1.tgz",+ "integrity": "sha512-IIJdzbACbhJUJyMAqpA9E9gxp1Gv29TeQ3DtL+pepwP8Oq2WiqjOB2HbnEIs23h0ewdKIZRDI56yLro2eUO+DA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "requireindex": "^1.2.0"+ },+ "engines": {+ "node": "^12.22.0 || ^14.17.0 || >=16.0.0",+ "npm": ">=6",+ "yarn": ">=1"+ },+ "peerDependencies": {+ "@testing-library/dom": "^8.0.0 || ^9.0.0 || ^10.0.0",+ "eslint": "^6.8.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0"+ },+ "peerDependenciesMeta": {+ "@testing-library/dom": {+ "optional": true+ }+ }+ },"node_modules/eslint-plugin-jsx-a11y": {"version": "6.10.2","resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.10.2.tgz",@@ -6989,6 +7015,23 @@"semver": "bin/semver.js"}},+ "node_modules/eslint-plugin-testing-library": {+ "version": "7.16.2",+ "resolved": "https://registry.npmjs.org/eslint-plugin-testing-library/-/eslint-plugin-testing-library-7.16.2.tgz",+ "integrity": "sha512-8gleGnQXK2ZA3hHwjCwpYTZvM+9VsrJ+/9kDI8CjqAQGAdMQOdn/rJNu7ZySENuiWlGKQWyZJ4ZjEg2zamaRHw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@typescript-eslint/scope-manager": "^8.56.0",+ "@typescript-eslint/utils": "^8.56.0"+ },+ "engines": {+ "node": "^18.18.0 || ^20.9.0 || >=21.1.0"+ },+ "peerDependencies": {+ "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0"+ }+ },"node_modules/eslint-plugin-unused-imports": {"version": "4.3.0","resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-4.3.0.tgz",@@ -12339,6 +12382,16 @@"node": ">=0.10.0"}},+ "node_modules/requireindex": {+ "version": "1.2.0",+ "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz",+ "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=0.10.5"+ }+ },"node_modules/reselect": {"version": "5.2.0","resolved": "https://registry.npmjs.org/reselect/-/reselect-5.2.0.tgz",diff --git a/ui/litellm-dashboard/package.json b/ui/litellm-dashboard/package.jsonindex 62bf5fff4b4..67e85783f9f 100644--- a/ui/litellm-dashboard/package.json+++ b/ui/litellm-dashboard/package.json@@ -77,6 +77,8 @@"eslint": "9.39.2","eslint-config-next": "16.2.11","eslint-config-prettier": "10.1.8",+ "eslint-plugin-jest-dom": "5.10.1",+ "eslint-plugin-testing-library": "7.16.2","eslint-plugin-unused-imports": "4.3.0","jsdom": "27.4.0","knip": "5.83.1",