MCPcopy Create free account
hub / github.com/bvaughn/react-virtualized / dispatchWindowScroll

Function dispatchWindowScroll

lib/utils/test/scrollElement.ts:293–300  ·  view source on GitHub ↗

Dispatches a scroll event to the window (without `act()`).

()

Source from the content-addressed store, hash-verified

291
292/** Dispatches a scroll event to the window (without `act()`). */
293function dispatchWindowScroll() {
294 const event = new window.Event("scroll", { bubbles: true });
295 // Vitest's jsdom environment aliases the global `window` to `globalThis`, so the
296 // `currentTarget` of an event bubbling up to the (internal) jsdom Window is not `=== window`.
297 // Report the global `window` as the current target so that the scroll listeners recognize it.
298 Object.defineProperty(event, "currentTarget", { get: () => window });
299 document.dispatchEvent(event);
300}
301
302/**
303 * Mocks scrolling the window: `scrollX`/`scrollY` (initially 0), `innerHeight`/`innerWidth` and `scrollTo()`

Callers 2

mockWindowScrollingFunction · 0.70
scrollFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected