Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.3 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";

import { toToastText } from "@/shared/components/NotificationToast";

// Regression guard: a toast message/title that is NOT a string (e.g. a raw API
// error body — a Zod `.format()` object) must be coerced to a string. Rendering
// an object as a React child throws React #31 and freezes the whole page. This
// was the "test model → screen froze" bug on the provider page.

test("returns strings unchanged", () => {
  assert.equal(toToastText("hello"), "hello");
  assert.equal(toToastText(""), "");
});

test("returns empty string for null/undefined (never crashes render)", () => {
  assert.equal(toToastText(null), "");
  assert.equal(toToastText(undefined), "");
});

test("prefers a nested string .message on an object error body", () => {
  assert.equal(toToastText({ message: "Rate limited" }), "Rate limited");
});

test("JSON-stringifies an arbitrary object instead of throwing (Zod .format() shape)", () => {
  const zodish = { modelId: { _errors: ["Required"] }, _errors: [] };
  const out = toToastText(zodish);
  assert.equal(typeof out, "string");
  assert.ok(out.includes("_errors"));
});

test("coerces numbers/booleans to string", () => {
  assert.equal(toToastText(42), "42");
  assert.equal(toToastText(true), "true");
});