


























@@ -197,20 +197,28 @@ function renderInto(props: DreamingProps): HTMLDivElement {
197197return container;
198198}
199199200+function expectElement(container: Element, selector: string): Element {
201+const element = container.querySelector(selector);
202+expect(element).toBeInstanceOf(Element);
203+if (!(element instanceof Element)) {
204+throw new Error(`Expected element matching ${selector}`);
205+}
206+return element;
207+}
208+200209describe("dreaming view", () => {
201210it("renders the active dream scene chrome and status", () => {
202211const container = renderInto(buildProps({ dreamingOf: "reindexing old chats\u2026" }));
203212204-const svg = container.querySelector(".dreams__lobster svg");
205-expect(svg).not.toBeNull();
213+expectElement(container, ".dreams__lobster svg");
206214207215const zs = container.querySelectorAll(".dreams__z");
208216expect(zs.length).toBe(3);
209217210218const stars = container.querySelectorAll(".dreams__star");
211219expect(stars.length).toBe(12);
212220213-expect(container.querySelector(".dreams__moon")).not.toBeNull();
221+expectElement(container, ".dreams__moon");
214222215223const phases = [...container.querySelectorAll(".dreams__phase-name")].map((node) =>
216224node.textContent?.trim(),
@@ -225,7 +233,7 @@ describe("dreaming view", () => {
225233expect(buttons).not.toContain("Backfill");
226234expect(buttons).not.toContain("Reset");
227235expect(buttons).not.toContain("Clear Replayed");
228-expect(container.querySelector(".dreams__bubble")).not.toBeNull();
236+expectElement(container, ".dreams__bubble");
229237const text = container.querySelector(".dreams__bubble-text");
230238expect(text?.textContent).toBe("reindexing old chats\u2026");
231239const label = container.querySelector(".dreams__status-label");
@@ -243,7 +251,7 @@ describe("dreaming view", () => {
243251const idleContainer = renderInto(buildProps({ active: false }));
244252expect(idleContainer.querySelector(".dreams__bubble")).toBeNull();
245253expect(idleContainer.querySelector(".dreams__status-label")?.textContent).toBe("Dreaming Idle");
246-expect(idleContainer.querySelector(".dreams--idle")).not.toBeNull();
254+expectElement(idleContainer, ".dreams--idle");
247255248256const unknownPhaseContainer = renderInto(buildProps({ phases: undefined }));
249257const statuses = [...unknownPhaseContainer.querySelectorAll(".dreams__phase-next")].map(
@@ -375,8 +383,7 @@ describe("dreaming view", () => {
375383const title = container.querySelector(".dreams-diary__title");
376384expect(title?.textContent).toContain("Dream Diary");
377385378-const entry = container.querySelector(".dreams-diary__entry");
379-expect(entry).not.toBeNull();
386+expectElement(container, ".dreams-diary__entry");
380387const date = container.querySelector(".dreams-diary__date");
381388expect(date?.textContent).toContain("April 5, 2026");
382389const body = container.querySelector(".dreams-diary__para");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。