MCPcopy Create free account
hub / github.com/bvaughn/react-window / mockScrollPadding

Function mockScrollPadding

lib/utils/test/mockScrollPadding.ts:14–36  ·  view source on GitHub ↗
(
  getScrollPadding: (element: Element) => ScrollPadding | undefined
)

Source from the content-addressed store, hash-verified

12
13// jsdom doesn't support the scroll-padding properties, so tests specify computed values for elements
14export function mockScrollPadding(
15 getScrollPadding: (element: Element) => ScrollPadding | undefined
16) {
17 const getComputedStyle = window.getComputedStyle.bind(window);
18
19 vi.spyOn(window, "getComputedStyle").mockImplementation(
20 (element, pseudoElement) => {
21 const style = getComputedStyle(element, pseudoElement);
22 const padding = getScrollPadding(element);
23 if (!padding) {
24 return style;
25 }
26
27 return new Proxy(style, {
28 get(target, property) {
29 return property in padding
30 ? padding[property as keyof ScrollPadding]
31 : Reflect.get(target, property, target);
32 }
33 });
34 }
35 );
36}

Callers 2

Calls 1

getScrollPaddingFunction · 0.85

Tested by

no test coverage detected