This repository was archived by the owner on Oct 14, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathjest.setup.ts
More file actions
71 lines (62 loc) · 2.15 KB
/
Copy pathjest.setup.ts
File metadata and controls
71 lines (62 loc) · 2.15 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
import '@testing-library/jest-dom';
import { TextEncoder, TextDecoder } from 'util';
// .env is gitignored and never reaches CI, so tests that depend on
// NEXT_PUBLIC_DOCS_BASE_URL (e.g. buildDocsUrl) need it set here.
process.env.NEXT_PUBLIC_DOCS_BASE_URL = 'https://docs.dalgo.org';
// Polyfill structuredClone (jsdom does not provide it)
if (typeof global.structuredClone === 'undefined') {
global.structuredClone = <T>(value: T): T => JSON.parse(JSON.stringify(value));
}
// Polyfill TextEncoder/TextDecoder (required by jspdf/iobuffer)
global.TextEncoder = TextEncoder;
// @ts-expect-error - polyfilling globals
global.TextDecoder = TextDecoder;
// Global API mock - available in all tests
// Individual tests can use mockApiGet.mockResolvedValue() to set responses
jest.mock('@/lib/api', () => ({
apiGet: jest.fn(),
apiPost: jest.fn(),
apiPut: jest.fn(),
apiPatch: jest.fn(),
apiDelete: jest.fn(),
}));
// Mock window.matchMedia
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(),
})),
});
// Mock ResizeObserver
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
// Mock IntersectionObserver
global.IntersectionObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
// Mock hasPointerCapture for Radix UI Select (jsdom doesn't support this)
if (!Element.prototype.hasPointerCapture) {
Element.prototype.hasPointerCapture = jest.fn().mockReturnValue(false);
}
if (!Element.prototype.setPointerCapture) {
Element.prototype.setPointerCapture = jest.fn();
}
if (!Element.prototype.releasePointerCapture) {
Element.prototype.releasePointerCapture = jest.fn();
}
// Mock scrollIntoView for Radix UI Select (jsdom doesn't fully support this)
if (!Element.prototype.scrollIntoView) {
Element.prototype.scrollIntoView = jest.fn();
}