@@ -6,13 +6,6 @@ process.env.TZ = 'UTC';
66// Mock OAuth client ID and secret
77process . env . OAUTH_CLIENT_ID = 'FAKE_CLIENT_ID_123' ;
88
9- /**
10- * Primer React testing helpers
11- * Note: @primer/react/test-helpers uses Jest internally, so we provide our own mocks
12- * - https://primer.style/product/getting-started/react/#testing
13- * - https://github.com/primer/react/blob/main/packages/react/src/utils/test-helpers.tsx
14- */
15-
169/**
1710 * Gitify context bridge API
1811 */
@@ -51,72 +44,28 @@ window.gitify = {
5144 raiseNativeNotification : vi . fn ( ) ,
5245} ;
5346
54- // prevent ReferenceError: TextEncoder is not defined
55- // window.TextEncoder = TextEncoder;
56-
57- window . HTMLMediaElement . prototype . play = vi . fn ( ) ;
58-
59- // Mock window.matchMedia
60- Object . defineProperty ( window , 'matchMedia' , {
61- writable : true ,
62- value : vi . fn ( ) . mockImplementation ( ( query ) => ( {
63- matches : false ,
64- media : query ,
65- onchange : null ,
66- addListener : vi . fn ( ) ,
67- removeListener : vi . fn ( ) ,
68- addEventListener : vi . fn ( ) ,
69- removeEventListener : vi . fn ( ) ,
70- dispatchEvent : vi . fn ( ) ,
71- } ) ) ,
72- } ) ;
73-
74- // Mock IntersectionObserver for Primer React components
75- // class MockIntersectionObserver {
76- // observe = vi.fn();
77- // unobserve = vi.fn();
78- // disconnect = vi.fn();
79- // }
80- // (globalThis as Record<string, unknown>).IntersectionObserver =
81- // MockIntersectionObserver;
82-
83- // Mock HTMLMediaElement.play - must return a Promise
84- globalThis . HTMLMediaElement . prototype . play = vi
85- . fn ( )
86- . mockResolvedValue ( undefined ) ;
87-
88- // Mock ResizeObserver as a class (must be a constructor)
89- class MockResizeObserver {
90- observe = vi . fn ( ) ;
91- unobserve = vi . fn ( ) ;
92- disconnect = vi . fn ( ) ;
93- }
94- globalThis . ResizeObserver = MockResizeObserver ;
95-
96- // Mock adoptedStyleSheets for Primer React components
97- // // jsdom doesn't support adoptedStyleSheets, so we need to mock it
98- // Object.defineProperty(document, 'adoptedStyleSheets', {
99- // value: [],
100- // writable: true,
101- // configurable: true,
102- // });
103-
104- // Mock ShadowRoot adoptedStyleSheets for web components
105- // const originalAttachShadow = Element.prototype.attachShadow;
106- // Element.prototype.attachShadow = function (init: ShadowRootInit): ShadowRoot {
107- // const shadowRoot = originalAttachShadow.call(this, init);
108- // Object.defineProperty(shadowRoot, 'adoptedStyleSheets', {
109- // value: [],
110- // writable: true,
111- // configurable: true,
112- // });
113- // return shadowRoot;
114- // };
115-
47+ // Mock clipboard API
11648Object . defineProperty ( navigator , 'clipboard' , {
11749 value : {
11850 writeText : vi . fn ( ) . mockResolvedValue ( undefined ) ,
11951 readText : vi . fn ( ) . mockResolvedValue ( '' ) ,
12052 } ,
12153 configurable : true ,
12254} ) ;
55+
56+ /**
57+ * Primer React testing helpers
58+ * Note: @primer/react/test-helpers uses Jest internally, so we provide our own mocks
59+ * - https://primer.style/product/getting-started/react/#testing
60+ * - https://github.com/primer/react/blob/main/packages/react/src/utils/test-helpers.tsx
61+ */
62+
63+ // Mock `showPopover` used by Primer React TooltipV2
64+ if ( ! ( 'showPopover' in HTMLElement . prototype ) ) {
65+ ( HTMLElement . prototype as any ) . showPopover = vi . fn ( ) ;
66+ }
67+
68+ // Mock `hidePopover` used by Primer React TooltipV2
69+ if ( ! ( 'hidePopover' in HTMLElement . prototype ) ) {
70+ ( HTMLElement . prototype as any ) . hidePopover = vi . fn ( ) ;
71+ }
0 commit comments