-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.tsx
More file actions
117 lines (103 loc) · 3.1 KB
/
jest.setup.tsx
File metadata and controls
117 lines (103 loc) · 3.1 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
import React from 'react';
import '@testing-library/jest-dom';
jest.mock('next/image', () => ({
__esModule: true,
default: (props: any) => {
const { src, alt, width, height, className } = props;
return <img src={typeof src === 'string' ? src : ''} alt={alt} width={width} height={height} className={className} />;
},
}));
jest.mock('next/link', () => ({
__esModule: true,
default: ({ children, href, className, ...props }: { children: React.ReactNode; href: string; className?: string; [key: string]: any }) => {
return <a href={href} className={className} {...props}>{children}</a>;
},
}));
jest.mock('next/navigation', () => ({
useRouter() {
return {
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
};
},
usePathname() {
return '';
},
useSearchParams() {
return new URLSearchParams();
},
}));
// Animation testing mocks
// Mock IntersectionObserver for animation testing
class MockIntersectionObserver {
constructor(callback: IntersectionObserverCallback, options?: IntersectionObserverInit) {
this.callback = callback;
this.options = options;
}
callback: IntersectionObserverCallback;
options?: IntersectionObserverInit;
root: Element | null = null;
rootMargin: string = '';
thresholds: ReadonlyArray<number> = [];
observe = jest.fn();
unobserve = jest.fn();
disconnect = jest.fn();
takeRecords = jest.fn(() => []);
}
// Mock performance API for animation performance testing
Object.defineProperty(window, 'performance', {
value: {
now: jest.fn(() => Date.now()),
mark: jest.fn(),
measure: jest.fn(),
getEntriesByType: jest.fn(() => []),
getEntriesByName: jest.fn(() => []),
},
writable: true,
});
// Mock requestAnimationFrame for animation testing
Object.defineProperty(window, 'requestAnimationFrame', {
value: jest.fn((callback) => {
return setTimeout(callback, 16); // ~60fps
}),
writable: true,
});
Object.defineProperty(window, 'cancelAnimationFrame', {
value: jest.fn((id) => {
clearTimeout(id);
}),
writable: true,
});
// Mock ResizeObserver for animation testing
class MockResizeObserver {
constructor(callback: ResizeObserverCallback) {
this.callback = callback;
}
callback: ResizeObserverCallback;
observe = jest.fn();
unobserve = jest.fn();
disconnect = jest.fn();
}
// Set up global mocks
Object.defineProperty(window, 'IntersectionObserver', {
value: MockIntersectionObserver,
writable: true,
});
Object.defineProperty(window, 'ResizeObserver', {
value: MockResizeObserver,
writable: true,
});
// Mock matchMedia for responsive animation testing
Object.defineProperty(window, 'matchMedia', {
value: jest.fn(() => ({
matches: false,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
writable: true,
});