-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.js
More file actions
84 lines (73 loc) 路 2.06 KB
/
Copy pathjest.js
File metadata and controls
84 lines (73 loc) 路 2.06 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
import '@testing-library/jest-dom';
import '@localization/config';
import { TextEncoder, TextDecoder } from 'util';
globalThis.TextEncoder = TextEncoder;
globalThis.TextDecoder = TextDecoder;
// Polyfill structuredClone for Jest jsdom environment (required by Chakra UI v3)
// jsdom may not expose Node's native structuredClone
if (typeof globalThis.structuredClone === 'undefined') {
// Use a robust deep clone that handles edge cases
globalThis.structuredClone = function structuredClone(obj) {
if (obj === undefined || obj === null) return obj;
try {
return JSON.parse(JSON.stringify(obj));
} catch {
return obj;
}
};
}
// Polyfill ResizeObserver for Chakra UI v3
if (typeof globalThis.ResizeObserver === 'undefined') {
globalThis.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};
}
jest.useFakeTimers();
jest.mock('zustand');
// Font source mocks.
jest.mock('@fontsource-variable/outfit', () => ({
__esModule: true,
default: 'outfit',
}));
jest.mock('@fontsource-variable/inter', () => ({
__esModule: true,
default: 'inter',
}));
jest.mock('@fontsource-variable/jetbrains-mono', () => ({
__esModule: true,
default: 'jetbrains-mono',
}));
/**
* Mock helmet module
*/
jest.mock('react-helmet-async', () => ({
Helmet: jest.fn(({ children }) => <>{children}</>),
HelmetProvider: ({ children }) => <>{children}</>,
}));
// Polyfill IntersectionObserver for tests
if (typeof globalThis.IntersectionObserver === 'undefined') {
globalThis.IntersectionObserver = class IntersectionObserver {
constructor() {}
observe() {}
unobserve() {}
disconnect() {}
};
}
/**
* Mock next-themes for test environment
*/
jest.mock('next-themes', () => ({
ThemeProvider: ({ children }) => children,
useTheme: () => ({
resolvedTheme: 'dark',
theme: 'dark',
setTheme: jest.fn(),
}),
}));
// React markdown preview mock.
jest.mock('@uiw/react-markdown-preview', () => ({
__esModule: true,
default: ({ source }) => <div data-testid="markdown-preview">{source}</div>,
}));