From 4e9278ea2f9ac8e883d8a9bfad9de0320a8f1dd6 Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:25:07 -0700 Subject: [PATCH] test(web): the diff loading boundary's observer counter lives in its fixture Co-Authored-By: Claude Opus 5.5 --- .../DiffFileLoadingBoundary.browser.test.tsx | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/apps/web/src/components/diffs/DiffFileLoadingBoundary.browser.test.tsx b/apps/web/src/components/diffs/DiffFileLoadingBoundary.browser.test.tsx index 4cffc00fad9ce..0bfb3c6539480 100644 --- a/apps/web/src/components/diffs/DiffFileLoadingBoundary.browser.test.tsx +++ b/apps/web/src/components/diffs/DiffFileLoadingBoundary.browser.test.tsx @@ -3,31 +3,34 @@ import { describe, expect, it, vi } from "vite-plus/test"; import { render } from "../../../test/render"; import { DiffFileLoadingBoundary } from "./DiffFileLoadingBoundary"; -// Like the real observer, every observe() reports the target's current state; this boundary -// is always in range. -class InRangeIntersectionObserver { - static observeCount = 0; - constructor(readonly callback: IntersectionObserverCallback) {} - observe(target: Element) { - InRangeIntersectionObserver.observeCount += 1; - this.callback( - [{ target, isIntersecting: true } as IntersectionObserverEntry], - this as unknown as IntersectionObserver, - ); - } - unobserve() {} - disconnect() {} -} - function stubIntersectionObserver() { - InRangeIntersectionObserver.observeCount = 0; + let observeCount = 0; + // Like the real observer, every observe() reports the target's current state; this boundary + // is always in range. + class InRangeIntersectionObserver { + constructor(readonly callback: IntersectionObserverCallback) {} + observe(target: Element) { + observeCount += 1; + this.callback( + [{ target, isIntersecting: true } as IntersectionObserverEntry], + this as unknown as IntersectionObserver, + ); + } + unobserve() {} + disconnect() {} + } vi.stubGlobal("IntersectionObserver", InRangeIntersectionObserver); - return { [Symbol.dispose]: () => vi.unstubAllGlobals() }; + return { + get observeCount() { + return observeCount; + }, + [Symbol.dispose]: () => vi.unstubAllGlobals(), + }; } describe("DiffFileLoadingBoundary", () => { it("observes once and loads once while its parent re-renders with a new load", async () => { - using _observer = stubIntersectionObserver(); + using observer = stubIntersectionObserver(); const load = vi.fn(); // DiffPanel hands over a new loadNextFiles whenever any file patch changes. await using screen = await render( load()} count={8} />, { @@ -38,12 +41,12 @@ describe("DiffFileLoadingBoundary", () => { await screen.rerender( load()} count={8} />); await expect.element(screen.getByRole("status", { name: "Loading diff…" })).toBeInTheDocument(); - expect(InRangeIntersectionObserver.observeCount).toBe(1); + expect(observer.observeCount).toBe(1); expect(load).toHaveBeenCalledTimes(1); // A settled batch leaves the boundary in range, so it asks for the next one. await screen.rerender( load()} count={4} />); - expect(InRangeIntersectionObserver.observeCount).toBe(1); + expect(observer.observeCount).toBe(1); expect(load).toHaveBeenCalledTimes(2); }); });