-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjest.setup.ts
More file actions
109 lines (99 loc) ยท 3.11 KB
/
Copy pathjest.setup.ts
File metadata and controls
109 lines (99 loc) ยท 3.11 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
// DOM ํ
์คํธ์ ํ์ฅ ๋งค์ฒ ์ถ๊ฐ
import "@testing-library/jest-dom";
import "jest-canvas-mock";
import React from "react";
// ๐ง ๋ธ๋ผ์ฐ์ ๋ด์ฅ ๊ฐ์ฒด Mock --------------------------------------------------
// alert / confirm / prompt ๋ฑ ๊ธฐ๋ณธ ๋ธ๋ผ์ฐ์ ํ์
ํจ์ mock
global.alert = jest.fn();
global.confirm = jest.fn(() => true); // ๊ธฐ๋ณธ์ "ํ์ธ" ์ ํ
global.prompt = jest.fn(() => ""); // ๋น ๋ฌธ์์ด ์
๋ ฅ ๋ฐํ
// scrollTo mock - jsdom์ ๊ธฐ๋ณธ ๊ตฌํ ์์
Object.defineProperty(window, "scrollTo", {
value: jest.fn(),
writable: true,
});
// ResizeObserver mock
class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
window.ResizeObserver = window.ResizeObserver || ResizeObserver;
// matchMedia mock - ์ผ๋ถ ์ฐจํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฑ์์ ์ฌ์ฉ
window.matchMedia =
window.matchMedia ||
function () {
return {
matches: false,
media: "",
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
};
};
// ๐ง ์ฝ์ ๊ด๋ จ ์ฒ๋ฆฌ ----------------------------------------------------------
// ์๋ฌ ๋ก๊ทธ, ๊ฒฝ๊ณ ๋ก๊ทธ ๋ฌด์ (ํ
์คํธ ๋
ธ์ด์ฆ ์ ๊ฑฐ)
global.console = {
...console,
error: jest.fn(),
warn: jest.fn(),
};
// ๐ง FullCalendar Mock -----------------------------------------------------
// FullCalendar React ์ปดํฌ๋ํธ ๋ชจํน
jest.mock("@fullcalendar/react", () => {
return function MockFullCalendar(props: any) {
return React.createElement(
"div",
{
"data-testid": "full-calendar",
className: "mock-fullcalendar",
},
[
// ์ด๋ฒคํธ๋ค ๋ ๋๋ง
...(props.events || []).map((event: any) =>
React.createElement(
"div",
{
key: event.id,
"data-testid": `event-${event.id}`,
className: "fc-event",
onClick: () => props.eventClick?.({ event }),
style: {
backgroundColor: event.backgroundColor,
borderColor: event.borderColor,
},
},
event.title
)
),
// ๋ ์ง ์
(ํด๋ฆญ ํ
์คํธ์ฉ) - ํญ์ selected-date ํด๋์ค ํฌํจ
React.createElement(
"div",
{
key: "calendar-cell",
"data-testid": "calendar-cell",
className: "fc-daygrid-day selected-date", // ์ฌ๊ธฐ์ selected-date ํด๋์ค ๋ช
์์ ์ผ๋ก ์ถ๊ฐ
onClick: () =>
props.dateClick?.({
date: new Date(props.selectedDate || "2024-06-01"),
dateStr: props.selectedDate || "2024-06-01",
}),
},
"1"
),
]
);
};
});
// FullCalendar ํ๋ฌ๊ทธ์ธ๋ค ๋ชจํน
jest.mock("@fullcalendar/daygrid", () => ({}));
jest.mock("@fullcalendar/interaction", () => ({
DateClickArg: {},
}));
jest.mock("@fullcalendar/core", () => ({
EventClickArg: {},
}));
jest.mock("@fullcalendar/core/locales/ko", () => ({}));