-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.ts
More file actions
52 lines (46 loc) · 1.04 KB
/
jest.setup.ts
File metadata and controls
52 lines (46 loc) · 1.04 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
/**
* Jest setup file
* This file is executed before each test file
*/
import '@testing-library/jest-dom';
import React from 'react';
type MockNextImageProps = React.ComponentPropsWithoutRef<'img'> & {
priority?: boolean;
fill?: boolean;
};
// Mock Next.js Image component
jest.mock('next/image', () => ({
__esModule: true,
default: (props: MockNextImageProps) => {
const normalizedProps = { ...props };
delete normalizedProps.priority;
delete normalizedProps.fill;
return React.createElement('img', normalizedProps);
},
}));
// Mock Next.js router
jest.mock('next/navigation', () => ({
useRouter() {
return {
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
pathname: '/',
query: {},
asPath: '/',
};
},
usePathname() {
return '/';
},
useSearchParams() {
return new URLSearchParams();
},
}));
// Suppress console errors in tests (optional)
// global.console = {
// ...console,
// error: jest.fn(),
// warn: jest.fn(),
// };