-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
123 lines (115 loc) · 3.68 KB
/
jest.setup.js
File metadata and controls
123 lines (115 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import '@testing-library/jest-dom'
import React from 'react'
// Mock window.matchMedia - only if window exists (browser environment)
if (typeof window !== 'undefined') {
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
})
}
// Polyfill pour React.act avec React 19
if (!React.act) {
React.act = (callback) => {
const result = callback()
if (result && typeof result.then === 'function') {
return result
}
return Promise.resolve(result)
}
}
// Mock framer-motion for tests - pass through components without animation
jest.mock('framer-motion', () => {
const React = require('react')
const actualReact = jest.requireActual('react')
return {
motion: {
create: (Component) => {
// Return a functional component that wraps the original component
const MotionWrapper = actualReact.forwardRef((props, ref) => {
return actualReact.createElement(Component, { ...props, ref })
})
MotionWrapper.displayName = `Motion(${Component.displayName || Component.name || 'Component'})`
return MotionWrapper
},
div: ({ children, ...props }) => actualReact.createElement('div', props, children),
section: ({ children, ...props }) => actualReact.createElement('section', props, children),
header: ({ children, ...props }) => actualReact.createElement('header', props, children),
nav: ({ children, ...props }) => actualReact.createElement('nav', props, children),
footer: ({ children, ...props }) => actualReact.createElement('footer', props, children),
button: ({ children, ...props }) => actualReact.createElement('button', props, children),
span: ({ children, ...props }) => actualReact.createElement('span', props, children),
img: ({ children, ...props }) => actualReact.createElement('img', props, children),
a: ({ children, ...props }) => actualReact.createElement('a', props, children),
},
AnimatePresence: ({ children }) => children,
useAnimation: () => ({
start: jest.fn(),
stop: jest.fn(),
}),
}
})
// Mock MUI theme and media queries
jest.mock('@mui/material', () => {
const actual = jest.requireActual('@mui/material')
return {
...actual,
useTheme: () => ({
breakpoints: {
down: () => false,
up: () => true,
between: () => false,
},
palette: {
mode: 'light',
primary: { main: '#1976d2' },
secondary: { main: '#dc004e' },
},
}),
useMediaQuery: () => false,
}
})
// Mock Next.js Image component
jest.mock('next/image', () => ({
__esModule: true,
default: (props) => {
// eslint-disable-next-line jsx-a11y/alt-text
return <img {...props} />
},
}))
// Mock next/navigation
jest.mock('next/navigation', () => ({
usePathname: () => '/',
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
}),
useSearchParams: () => new URLSearchParams(),
}))
// Suppress console warnings in tests
const originalError = console.error
beforeAll(() => {
console.error = (...args) => {
if (
typeof args[0] === 'string' &&
(args[0].includes('ReactDOMTestUtils.act') ||
args[0].includes('Not implemented: HTMLFormElement.prototype.requestSubmit') ||
args[0].includes('useLayoutEffect'))
) {
return
}
originalError.call(console, ...args)
}
})
afterAll(() => {
console.error = originalError
})