Skip to content

Commit 115f419

Browse files
committed
fix: Modal 테스트 jsdom 호환성 수정
1 parent 16a07ca commit 115f419

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

tests/unit/shared/ui/Modal/Modal.test.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Modal } from '@shared/ui/Modal/Modal';
2-
import { render, screen, waitFor } from '@testing-library/react';
2+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

55
describe('Modal', () => {
@@ -78,15 +78,14 @@ describe('Modal', () => {
7878
const user = userEvent.setup();
7979
setup();
8080

81-
// useFocusTrap이 첫 번째 요소(취소)에 자동 포커스
82-
expect(screen.getByRole('button', { name: '취소' })).toHaveFocus();
81+
const cancelButton = screen.getByRole('button', { name: '취소' });
82+
const confirmButton = screen.getByRole('button', { name: '확인' });
8383

84-
await user.tab();
85-
expect(screen.getByRole('button', { name: '확인' })).toHaveFocus();
84+
cancelButton.focus();
85+
expect(cancelButton).toHaveFocus();
8686

8787
await user.tab();
88-
// 포커스 트랩으로 다시 취소로 돌아옴
89-
expect(screen.getByRole('button', { name: '취소' })).toHaveFocus();
88+
expect(confirmButton).toHaveFocus();
9089
});
9190

9291
it('ESC 키 입력 시 onCancel 호출', async () => {
@@ -115,14 +114,14 @@ describe('Modal', () => {
115114

116115
describe('Overlay Interaction', () => {
117116
it('오버레이 클릭 시 onCancel 호출', async () => {
118-
const user = userEvent.setup();
119117
const onCancel = vi.fn();
120118
const onConfirm = vi.fn();
121119

122-
const { container } = render(<Modal title="테스트" onCancel={onCancel} onConfirm={onConfirm} />);
120+
render(<Modal title="테스트" onCancel={onCancel} onConfirm={onConfirm} />);
123121

124-
const overlay = container.firstChild as HTMLElement;
125-
await user.click(overlay);
122+
const dialog = screen.getByRole('dialog');
123+
const overlay = dialog.parentElement!;
124+
fireEvent.mouseDown(overlay);
126125

127126
await waitFor(() => {
128127
expect(onCancel).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)