@@ -3,74 +3,15 @@ import { cleanup } from "@testing-library/react";
33import { afterEach , vi } from "vitest" ;
44import failOnConsole from "vitest-fail-on-console" ;
55
6- // Mock CSS imports
7- vi . mock ( "*.css" , ( ) => ( { } ) ) ;
8- vi . mock ( "katex/dist/katex.min.css" , ( ) => ( { } ) ) ;
9-
10- // Mock ResizeObserver
11- global . ResizeObserver = vi . fn ( function ( this : ResizeObserver ) {
12- this . observe = vi . fn ( ) ;
13- this . unobserve = vi . fn ( ) ;
14- this . disconnect = vi . fn ( ) ;
15- return this ;
16- } ) as unknown as typeof ResizeObserver ;
17-
18- // Mock IntersectionObserver
19- global . IntersectionObserver = vi . fn ( function ( this : IntersectionObserver ) {
20- this . observe = vi . fn ( ) ;
21- this . unobserve = vi . fn ( ) ;
22- this . disconnect = vi . fn ( ) ;
23- this . root = null ;
24- this . rootMargin = "" ;
25- this . thresholds = [ ] ;
26- this . takeRecords = vi . fn ( ( ) => [ ] ) ;
27- return this ;
28- } ) as unknown as typeof IntersectionObserver ;
29-
30- // Mock matchMedia
31- Object . defineProperty ( window , "matchMedia" , {
6+ // Mock clipboard API for browser environment
7+ Object . defineProperty ( navigator , "clipboard" , {
8+ value : {
9+ writeText : vi . fn ( ( ) => Promise . resolve ( ) ) ,
10+ } ,
3211 writable : true ,
33- value : vi . fn ( ) . mockImplementation ( ( query ) => ( {
34- matches : false ,
35- media : query ,
36- onchange : null ,
37- addListener : vi . fn ( ) ,
38- removeListener : vi . fn ( ) ,
39- addEventListener : vi . fn ( ) ,
40- removeEventListener : vi . fn ( ) ,
41- dispatchEvent : vi . fn ( ) ,
42- } ) ) ,
12+ configurable : true ,
4313} ) ;
4414
45- // Patch createElement to handle SVG elements properly in jsdom
46- const SVG_TAGS = new Set ( [
47- "svg" ,
48- "path" ,
49- "circle" ,
50- "g" ,
51- "rect" ,
52- "line" ,
53- "polyline" ,
54- "polygon" ,
55- "ellipse" ,
56- "text" ,
57- "tspan" ,
58- "defs" ,
59- "clipPath" ,
60- ] ) ;
61-
62- const originalCreateElement = document . createElement . bind ( document ) ;
63- // @ts -expect-error - Overriding createElement signature for test environment
64- document . createElement = (
65- tagName : string ,
66- options ?: ElementCreationOptions
67- ) => {
68- if ( SVG_TAGS . has ( tagName . toLowerCase ( ) ) ) {
69- return document . createElementNS ( "http://www.w3.org/2000/svg" , tagName ) ;
70- }
71- return originalCreateElement ( tagName , options ) ;
72- } ;
73-
7415// Fail the test if there are any console logs during test execution
7516failOnConsole ( {
7617 shouldFailOnAssert : true ,
0 commit comments