-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjest.setup.ts
More file actions
51 lines (46 loc) · 1.31 KB
/
jest.setup.ts
File metadata and controls
51 lines (46 loc) · 1.31 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
import '@testing-library/jest-dom';
import { TextEncoder, TextDecoder } from 'util';
/**
* Suppress console output during tests for cleaner test output.
* Only error and fatal logs are shown to catch actual errors.
*/
global.console = {
...console,
log: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
debug: jest.fn(),
trace: jest.fn(),
};
/**
* Mock the timezone module to avoid calling cookies() outside request scope.
* Returns UTC (offset=0) by default. Tests can override using jest.mocked().
*/
jest.mock('@/lib/timezone', () => ({
TIMEZONE_COOKIE_NAME: 'oar-tz-offset',
DEFAULT_TIMEZONE_OFFSET_HOURS: 0,
getUserTimezoneOffset: jest.fn().mockResolvedValue(0),
}));
/**
* Mock ResizeObserver for Radix UI components and other UI libraries.
*/
global.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};
/**
* Mock PointerEvent for Radix UI components (required for many interactions).
*/
if (!global.PointerEvent) {
(global as unknown as Record<string, unknown>).PointerEvent = class PointerEvent extends Event {
constructor(type: string, params: Record<string, unknown> = {}) {
super(type, params);
}
};
}
/**
* Mock TextEncoder/TextDecoder for Next.js server components.
*/
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;