Files
clean-architecture-frontend…/tests/component/boot-unexpected-failure.test.tsx
T
DongHyeonka 1b1d972acd test(boot): 예상 밖 부팅 실패 테스트가 바꾼 전역 reportError를 되돌린다
문제
tests/component/boot-unexpected-failure.test.tsx는 vi.stubGlobal로
reportError를 바꾸고 되돌리지 않는다. 설정에 unstubGlobals가 없어서 그 stub이
같은 파일의 다음 테스트에 남는다.

고른 방법
- 이 파일에 afterEach(vi.unstubAllGlobals)를 둔다. 전역 설정
  (unstubGlobals: true)은 다른 파일의 동작까지 바꾸므로 고르지 않았다.

검증
- 파일 2건 통과, eslint 통과.

Refs: docs/reviews/2026-11-03-maturity-review/10-tests-fast-layers.md (2절 boot-unexpected-failure stubGlobal)
2026-11-04 21:23:37 +09:00

59 lines
2.2 KiB
TypeScript

// @vitest-environment jsdom
import { render, screen, within } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { BootErrorShell } from "../../src/presentation/boundaries/boot-error-shell.tsx";
// 09-04. An assembly defect (here the TypeError a missing feature capability
// used to produce) was shown as BOOT_CONFIG_FAILURE and the error was dropped.
const assemblyDefect = new TypeError(
"Cannot read properties of undefined (reading 'get')",
);
vi.mock("../../src/bootstrap/create-runtime-composition.ts", () => ({
createRuntimeComposition: async () => {
throw assemblyDefect;
},
}));
// The reportError stub must not reach the next test in this file; the config
// does not set unstubGlobals.
afterEach(() => {
vi.unstubAllGlobals();
});
describe("unexpected boot failure (09-04)", () => {
it("is shown as BOOT_UNEXPECTED_FAILURE and reports the error in development", async () => {
document.body.innerHTML =
'<div id="root"><div role="status" data-boot-shell="">불러오는 중</div></div>';
// jsdom has no reportError; browsers do.
const reportError = vi.fn<(error: unknown) => void>();
vi.stubGlobal("reportError", reportError);
await import("../../src/bootstrap/main.tsx");
const shell = await screen.findByRole("alert");
expect(shell).toHaveTextContent("BOOT_UNEXPECTED_FAILURE");
expect(shell).not.toHaveTextContent("BOOT_CONFIG_FAILURE");
expect(shell).toHaveTextContent("local-build");
expect(shell).toHaveTextContent("TypeError");
expect(shell).not.toHaveTextContent("reading 'get'");
expect(reportError).toHaveBeenCalledWith(assemblyDefect);
});
it("lists the rejected configuration keys", () => {
const view = render(
<BootErrorShell
kind="BOOT_CONFIG_FAILURE"
code="CONFIG_SCHEMA_INVALID"
buildId="build-a"
invalidKeys={["TELEMETRY_ENABELD"]}
supportReference="build-a:CONFIG_SCHEMA_INVALID"
/>,
);
const shell = within(view.container).getByRole("alert");
expect(within(shell).getByText("잘못된 설정 키")).toBeInTheDocument();
expect(shell).toHaveTextContent("TELEMETRY_ENABELD");
});
});