// @vitest-environment jsdom // // A render crash's notice speaks the reader's language. It showed `error.message` — the JS // engine's English ("Cannot read properties of undefined (reading 'x')") — in the toast and the inbox, // where it outlives the reload. The technical text stays in the `ui.crash` log. import { afterEach, expect, it, vi } from "vitest"; import { cleanup, render } from "@testing-library/react"; const notify = vi.fn(); vi.mock("../lib/notifications", () => ({ notify: (...args: unknown[]) => notify(...args) })); import i18n from "../i18n"; import { clear, events } from "../lib/log"; import ErrorBoundary from "./ErrorBoundary"; afterEach(() => { cleanup(); clear(); vi.restoreAllMocks(); }); it("a crash is reported in words the reader reads; the engine's text goes to the log", () => { vi.spyOn(console, "error").mockImplementation(() => {}); // React reports the throw itself too const Broken = () => { throw new TypeError("Cannot read properties of undefined (reading 'x')"); }; render( , ); expect(notify).toHaveBeenCalledWith( expect.objectContaining({ level: "fatal", message: i18n.t("errors.boundary.notifMessage") }), ); expect(JSON.stringify(events().filter((e) => e.event === "ui.crash"))).toContain( "Cannot read properties of undefined", ); });