Skip to content

Commit 55eaad0

Browse files
committed
test: 로그인 모달 컴포넌트 테스트 추가
1 parent 8db1074 commit 55eaad0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/widgets/auth/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
/* v8 ignore start */
12
export { default as LoginModal } from './ui/LoginModal';
3+
/* v8 ignore end */
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { describe, expect, it, vi } from 'vitest';
3+
4+
import userEvent from '@testing-library/user-event';
5+
import LoginModal from '.';
6+
7+
const navigate = vi.fn();
8+
9+
vi.mock('react-router', () => ({
10+
useNavigate: () => navigate,
11+
}));
12+
13+
describe('LoginModal 컴포넌트 테스트', () => {
14+
it('LoginModal이 렌더링된다.', () => {
15+
render(<LoginModal />);
16+
17+
const loginModal = screen.getByRole('dialog');
18+
19+
expect(loginModal).toBeInTheDocument();
20+
});
21+
22+
it('Backdrop을 클릭하면 navigate가 호출된다.', async () => {
23+
const user = userEvent.setup();
24+
render(<LoginModal />);
25+
26+
const backdrop = screen.getByTestId('backdrop');
27+
28+
await user.click(backdrop);
29+
30+
expect(navigate).toHaveBeenNthCalledWith(1, -1);
31+
});
32+
});

0 commit comments

Comments
 (0)