1+ // jest-dom adds custom jest matchers for asserting on DOM nodes.
2+ // allows you to do things like:
3+ // expect(element).toHaveTextContent(/react/i)
4+ // learn more: https://github.com/testing-library/jest-dom
5+ import '@testing-library/jest-dom' ;
6+
7+ // Mock the ogl library to prevent ES6 module parsing issues
8+ jest . mock ( 'ogl' , ( ) => {
9+ const mockGl = {
10+ canvas : { width : 800 , height : 600 } ,
11+ clearColor : jest . fn ( ) ,
12+ viewport : jest . fn ( ) ,
13+ enable : jest . fn ( ) ,
14+ blendFunc : jest . fn ( ) ,
15+ POINTS : 0 ,
16+ createProgram : jest . fn ( ( ) => ( {
17+ use : jest . fn ( ) ,
18+ setUniform : jest . fn ( ) ,
19+ } ) ) ,
20+ createBuffer : jest . fn ( ( ) => ( {
21+ bind : jest . fn ( ) ,
22+ update : jest . fn ( ) ,
23+ } ) ) ,
24+ createVertexArray : jest . fn ( ( ) => ( {
25+ bind : jest . fn ( ) ,
26+ setAttribute : jest . fn ( ) ,
27+ } ) ) ,
28+ } ;
29+
30+ const mockRenderer = jest . fn ( ) . mockImplementation ( ( ) => ( {
31+ setSize : jest . fn ( ) ,
32+ render : jest . fn ( ) ,
33+ dispose : jest . fn ( ) ,
34+ gl : mockGl ,
35+ } ) ) ;
36+
37+ const mockCamera = jest . fn ( ) . mockImplementation ( ( ) => ( {
38+ position : { set : jest . fn ( ) } ,
39+ lookAt : jest . fn ( ) ,
40+ matrix : { elements : new Array ( 16 ) . fill ( 0 ) } ,
41+ perspective : jest . fn ( ) ,
42+ } ) ) ;
43+
44+ const mockGeometry = jest . fn ( ) . mockImplementation ( ( ) => ( {
45+ setAttribute : jest . fn ( ) ,
46+ setIndex : jest . fn ( ) ,
47+ } ) ) ;
48+
49+ const mockProgram = jest . fn ( ) . mockImplementation ( ( ) => ( {
50+ bind : jest . fn ( ) ,
51+ setUniform : jest . fn ( ) ,
52+ uniforms : {
53+ uTime : { value : 0 } ,
54+ uSpread : { value : 1 } ,
55+ uBaseSize : { value : 1 } ,
56+ uSizeRandomness : { value : 1 } ,
57+ uAlphaParticles : { value : 0 } ,
58+ } ,
59+ } ) ) ;
60+
61+ const mockMesh = jest . fn ( ) . mockImplementation ( ( ) => ( {
62+ setParent : jest . fn ( ) ,
63+ setProgram : jest . fn ( ) ,
64+ setGeometry : jest . fn ( ) ,
65+ position : { x : 0 , y : 0 , z : 0 } ,
66+ rotation : { x : 0 , y : 0 , z : 0 } ,
67+ } ) ) ;
68+
69+ return {
70+ Renderer : mockRenderer ,
71+ Camera : mockCamera ,
72+ Geometry : mockGeometry ,
73+ Program : mockProgram ,
74+ Mesh : mockMesh ,
75+ } ;
76+ } ) ;
77+
78+ // Mock window.requestAnimationFrame
79+ global . requestAnimationFrame = jest . fn ( ( callback ) => {
80+ setTimeout ( callback , 0 ) ;
81+ return 1 ;
82+ } ) ;
83+
84+ // Mock window.cancelAnimationFrame
85+ global . cancelAnimationFrame = jest . fn ( ) ;
86+
87+ // Mock performance.now
88+ global . performance = {
89+ ...global . performance ,
90+ now : jest . fn ( ( ) => Date . now ( ) ) ,
91+ } ;
92+
93+ // Mock CSS modules - using moduleNameMapper approach instead of jest.mock
94+
95+ // Mock framer-motion to prevent animation-related issues in tests
96+ jest . mock ( 'framer-motion' , ( ) => ( {
97+ motion : {
98+ div : ( { children, ...props } ) => < div { ...props } > { children } </ div > ,
99+ span : ( { children, ...props } ) => < span { ...props } > { children } </ span > ,
100+ button : ( { children, ...props } ) => < button { ...props } > { children } </ button > ,
101+ } ,
102+ animate : jest . fn ( ) ,
103+ useMotionValue : jest . fn ( ( ) => ( { get : jest . fn ( ) , set : jest . fn ( ) , jump : jest . fn ( ) } ) ) ,
104+ useMotionValueEvent : jest . fn ( ) ,
105+ useTransform : jest . fn ( ( ) => ( { get : jest . fn ( ) } ) ) ,
106+ } ) ) ;
107+
108+ // Mock react-simple-maps
109+ jest . mock ( 'react-simple-maps' , ( ) => ( {
110+ ComposableMap : ( { children } ) => < div data-testid = "composable-map" > { children } </ div > ,
111+ Geographies : ( { children } ) => < div data-testid = "geographies" > { children } </ div > ,
112+ Geography : ( { children } ) => < div data-testid = "geography" > { children } </ div > ,
113+ ZoomableGroup : ( { children } ) => < div data-testid = "zoomable-group" > { children } </ div > ,
114+ Marker : ( { children } ) => < div data-testid = "marker" > { children } </ div > ,
115+ } ) ) ;
116+
117+ // Mock react-force-graph
118+ jest . mock ( 'react-force-graph' , ( ) => {
119+ return function MockForceGraph ( ) {
120+ return < div data-testid = "force-graph" /> ;
121+ } ;
122+ } ) ;
123+
124+ jest . mock ( 'react-force-graph-2d' , ( ) => {
125+ return function MockForceGraph2D ( ) {
126+ return < div data-testid = "force-graph-2d" /> ;
127+ } ;
128+ } ) ;
129+
130+ // Mock recharts
131+ jest . mock ( 'recharts' , ( ) => ( {
132+ LineChart : ( { children } ) => < div data-testid = "line-chart" > { children } </ div > ,
133+ Line : ( { children } ) => < div data-testid = "line" > { children } </ div > ,
134+ XAxis : ( { children } ) => < div data-testid = "x-axis" > { children } </ div > ,
135+ YAxis : ( { children } ) => < div data-testid = "y-axis" > { children } </ div > ,
136+ CartesianGrid : ( { children } ) => < div data-testid = "cartesian-grid" > { children } </ div > ,
137+ Tooltip : ( { children } ) => < div data-testid = "tooltip" > { children } </ div > ,
138+ ResponsiveContainer : ( { children } ) => < div data-testid = "responsive-container" > { children } </ div > ,
139+ BarChart : ( { children } ) => < div data-testid = "bar-chart" > { children } </ div > ,
140+ Bar : ( { children } ) => < div data-testid = "bar" > { children } </ div > ,
141+ PieChart : ( { children } ) => < div data-testid = "pie-chart" > { children } </ div > ,
142+ Pie : ( { children } ) => < div data-testid = "pie" > { children } </ div > ,
143+ Cell : ( { children } ) => < div data-testid = "cell" > { children } </ div > ,
144+ } ) ) ;
145+
146+ // Mock tsparticles
147+ jest . mock ( 'tsparticles' , ( ) => ( {
148+ loadFull : jest . fn ( ) ,
149+ } ) ) ;
150+
151+ // Mock react-datepicker
152+ jest . mock ( 'react-datepicker' , ( ) => {
153+ return function MockDatePicker ( props ) {
154+ return < input data-testid = "datepicker" { ...props } /> ;
155+ } ;
156+ } ) ;
157+
158+ // Mock the Particles component specifically to avoid WebGL issues
159+ jest . mock ( './components/animated/SearchBackground/Particles' , ( ) => {
160+ return function MockParticles ( props ) {
161+ return < div data-testid = "particles" { ...props } /> ;
162+ } ;
163+ } ) ;
164+
165+ // Mock Float32Array and other WebGL-related constructors
166+ global . Float32Array = Float32Array ;
0 commit comments