forked from Lilly-Protocol/lily-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal-error.test.tsx
More file actions
38 lines (30 loc) · 1.21 KB
/
Copy pathglobal-error.test.tsx
File metadata and controls
38 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { fireEvent, render, screen } from "@testing-library/react";
import { renderToStaticMarkup } from "react-dom/server";
import { vi } from "vitest";
import GlobalError, { GlobalErrorPanel } from "./global-error";
vi.mock("next/font/google", () => ({
IBM_Plex_Mono: () => ({ variable: "font-ibm-plex-mono" }),
Space_Grotesk: () => ({ variable: "font-space-grotesk" }),
}));
describe("GlobalError", () => {
it("renders a full document error boundary with font variables", () => {
const reset = vi.fn();
const error = Object.assign(new Error("Font failed"), {
digest: "error-digest-123",
});
const markup = renderToStaticMarkup(
<GlobalError error={error} reset={reset} />,
);
expect(markup).toContain("<html");
expect(markup).toContain("font-space-grotesk");
expect(markup).toContain("font-ibm-plex-mono");
expect(markup).toContain("Digest: error-digest-123");
});
it("calls reset from the recovery action", () => {
const reset = vi.fn();
const error = new Error("Font failed");
render(<GlobalErrorPanel error={error} reset={reset} />);
fireEvent.click(screen.getByRole("button", { name: /try again/i }));
expect(reset).toHaveBeenCalledOnce();
});
});