-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
38 lines (34 loc) · 921 Bytes
/
jest.setup.js
File metadata and controls
38 lines (34 loc) · 921 Bytes
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
// jest.setup.js
require('@testing-library/jest-dom');
// Polyfill crypto pour les tests
const { webcrypto, randomUUID } = require('crypto');
global.crypto = {
...webcrypto,
randomUUID: randomUUID,
subtle: webcrypto.subtle,
};
// Mock Next.js router
jest.mock('next/navigation', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
pathname: '/',
query: {},
}),
usePathname: () => '/',
useSearchParams: () => new URLSearchParams(),
}));
// Mock Next.js image component
jest.mock('next/image', () => ({
__esModule: true,
default: (props) => {
const { priority, fill, src, ...rest } = props;
return <img src={typeof src === 'object' ? src.src : src} {...rest} alt={rest.alt || ''} />;
},
}));
// Mock pour fetch qui sera utilisé dans les tests
if (typeof global.fetch !== 'function') {
global.fetch = jest.fn();
}