-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Button): 유닛 테스트 코드를 작성합니다. (#152)
* feat(Button): Button 컴포넌트 테스트 코드 작성 * cs --------- Co-authored-by: Brokyeom <goindol40@gmail.com>
- Loading branch information
1 parent
cfa204b
commit ddd78ee
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sopt-makers/ui': patch | ||
--- | ||
|
||
Add Button Unit Test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |