Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344/** * jsdom gaps the views depend on, stubbed once so every view test exercises the * same code path as the browser. */import { vi } from "vitest";
export interface ResizeStub { /** what clientWidth reports — wide enough, the album grid gets real columns */ width?: number; /** what clientHeight reports — left at 0 to keep virtualizers window-thin */ height?: number;}
/** * jsdom ships neither ResizeObserver nor layout, which would let VirtualList and * AlbumGrid bail out of their observe/teardown branch (the branch that once * carried the CLEANUP_IN_FORBIDDEN_SCOPE bug) and report a 0-sized viewport. * * Width and height are stubbed separately on purpose: a test usually wants a * wide grid (real column math) but a short viewport (so rows below the fold * really are absent from the DOM before it scrolls to them). */export function stubResizeObserver({ width = 0, height = 0 }: ResizeStub = {}): void { class FakeResizeObserver { private cb: ResizeObserverCallback; constructor(cb: ResizeObserverCallback) { this.cb = cb; } observe(target: Element) { this.cb( [{ target, contentRect: {} } as ResizeObserverEntry], this as unknown as ResizeObserver, ); } unobserve(): void {} disconnect(): void {} } vi.stubGlobal("ResizeObserver", FakeResizeObserver); Object.defineProperties(HTMLElement.prototype, { clientWidth: { configurable: true, get: () => width }, clientHeight: { configurable: true, get: () => height }, });}