import { act, render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import type { HighlightedCodeProps } from "@/components/HighlightedCode"; import { CodeBlock } from "@/components/CodeBlock"; import { ThemeProvider } from "@/hooks/useTheme"; const failures = vi.hoisted(() => new Set()); // Test CodeBlock's controls and enhancement boundary here; token/DOM rendering has dedicated real-engine and browser coverage. vi.mock("@/components/HighlightedCode", () => ({ HighlightedCode: ({ code, language, viewportHighlight }: HighlightedCodeProps) => { if (failures.has(code)) throw new Error("Grammar download failed"); return
{code}
; }, })); describe("CodeBlock", () => { it("contains a failed grammar, preserves source and copy, and enhances changed source", async () => { const source = "; 中文 😀\r\n[server]\r\nhost=localhost\r\n"; failures.add(source); const user = userEvent.setup(); const writeText = vi.fn().mockResolvedValue(undefined); Object.defineProperty(navigator, "clipboard", { configurable: true, value: { writeText } }); const errors = vi.spyOn(console, "error").mockImplementation(() => {}); const warnings = vi.spyOn(console, "warn").mockImplementation(() => {}); try { const { rerender } = render(<>