Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion skills/testing/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: "React Testing Library 및 Vitest 기반 테스팅 모범 관례.
license: MIT
metadata:
author: DaleStudy
version: "1.0.1"
version: "1.1.0"
---

# Testing Library
Expand Down Expand Up @@ -158,6 +158,29 @@ await waitFor(() => {
expect(screen.getByText("Hello")).toBeInTheDocument();
```

### 4. getBy* + toBeInTheDocument() 제거

`getBy*`는 요소를 못 찾으면 throw하므로 `toBeInTheDocument()`는 기술적으로 중복이다. 하지만 **제거하지 마라** — 리팩토링 후 남은 쿼리가 아니라 의도적인 존재 검증임을 코드 독자에게 전달하는 역할을 한다.

```typescript
// ❌ 나쁜 예 - assertion 없이 쿼리만 남김
screen.getByRole("button", { name: /제출/i });

// ✅ 좋은 예 - 명시적 assertion으로 의도 전달
expect(screen.getByRole("button", { name: /제출/i })).toBeInTheDocument();
```

단, 존재 검증이 아닌 다른 속성을 검증할 때는 `toBeInTheDocument()`를 추가할 필요 없다:

```typescript
// ✅ 좋은 예 - 다른 matcher로 충분
expect(screen.getByRole("button", { name: /제출/i })).toBeDisabled();

// ❌ 나쁜 예 - 중복 assertion
expect(screen.getByRole("button", { name: /제출/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /제출/i })).toBeDisabled();
```

**전체 안티패턴 목록**: [references/common-mistakes.md](references/common-mistakes.md)

## Vitest + MSW 설정
Expand Down