Skip to content

Commit

Permalink
feat(Button): 유닛 테스트 코드를 작성합니다. (#152)
Browse files Browse the repository at this point in the history
* feat(Button): Button 컴포넌트 테스트 코드 작성

* cs

---------

Co-authored-by: Brokyeom <goindol40@gmail.com>
  • Loading branch information
jungwoo3490 and Brokyeom authored Sep 26, 2024
1 parent cfa204b commit ddd78ee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-planets-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sopt-makers/ui': patch
---

Add Button Unit Test.
29 changes: 29 additions & 0 deletions packages/ui/Button/test/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { render, screen, fireEvent } from '@testing-library/react';
import { it, expect, vi } from 'vitest';
import Button from '../Button';

it('Button 컴포넌트가 정상적으로 렌더링됩니다.', () => {
render(<Button>테스트 버튼</Button>);

expect(screen.getByText('테스트 버튼')).toBeInTheDocument();
});

it('버튼을 클릭했을 때 onClick 이벤트 핸들러가 정상적으로 호출됩니다.', () => {
const handleClick = vi.fn();
render(<Button onClick={handleClick}>테스트 버튼</Button>);

fireEvent.click(screen.getByText('테스트 버튼'));
expect(handleClick).toHaveBeenCalled();
});

it('disabled 상태에서 버튼을 클릭했을 때 onClick 이벤트 핸들러가 호출되지 않습니다.', () => {
const handleClick = vi.fn();
render(
<Button disabled onClick={handleClick}>
테스트 버튼
</Button>,
);

fireEvent.click(screen.getByText('테스트 버튼'));
expect(handleClick).not.toHaveBeenCalled();
});

0 comments on commit ddd78ee

Please sign in to comment.