본문으로 건너뛰기
Skillpedia
테스트40k · #7262

javascript-typescript-jest

하는 일

이 도구는 Jest 라이브러리를 사용해 JavaScript와 TypeScript 코드의 테스트를 만들도록 돕습니다. 테스트를 체계적으로 정리하고, 다른 것에 의존하는 코드 부분(외부 API 등)을 모의(mock)로 흉내 내며, 모든 것이 기대대로 작동하는지 확인하는 모범 사례를 가르칩니다.

사용하는 경우

  • ✓JavaScript나 TypeScript로 코드를 작성할 때.
  • ✓변경 후에도 코드가 올바르게 작동하도록 할 때.
  • ✓외부 의존성을 흉내 내고 내 로직만 테스트하고 싶을 때.

스킬 링크

https://github.com/github/awesome-copilot/blob/main/skills/javascript-typescript-jest/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/javascript-typescript-jest/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“외부 API를 호출하는 함수를 어떻게 테스트하나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

도구는 테스트를 특정 파일로 정리하고, `describe`와 `it` 같은 명령으로 테스트를 구조화합니다. 의존성을 흉내 내기 위해 `jest.mock`과 `jest.spyOn` 같은 함수를 사용해 가짜 버전을 만들어, 코드를 독립적으로 테스트할 수 있게 합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Test Structure

  • Name test files with .test.ts or .test.js suffix
  • Place test files next to the code they test or in a dedicated __tests__ directory
  • Use descriptive test names that explain the expected behavior
  • Use nested describe blocks to organize related tests
  • Follow the pattern: describe('Component/Function/Class', () => { it('should do something', () => {}) })

Effective Mocking

  • Mock external dependencies (APIs, databases, etc.) to isolate your tests
  • Use jest.mock() for module-level mocks
  • Use jest.spyOn() for specific function mocks
  • Use mockImplementation() or mockReturnValue() to define mock behavior
  • Reset mocks between tests with jest.resetAllMocks() in afterEach

Testing Async Code

  • Always return promises or use async/await syntax in tests
  • Use resolves/rejects matchers for promises
  • Set appropriate timeouts for slow tests with jest.setTimeout()

Snapshot Testing

  • Use snapshot tests for UI components or complex objects that change infrequently
  • Keep snapshots small and focused
  • Review snapshot changes carefully before committing

Testing React Components

  • Use React Testing Library over Enzyme for testing components
  • Test user behavior and component accessibility
  • Query elements by accessibility roles, labels, or text content
  • Use userEvent over fireEvent for more realistic user interactions

Common Jest Matchers

  • Basic: expect(value).toBe(expected), expect(value).toEqual(expected)
  • Truthiness: expect(value).toBeTruthy(), expect(value).toBeFalsy()
  • Numbers: expect(value).toBeGreaterThan(3), expect(value).toBeLessThanOrEqual(3)
  • Strings: expect(value).toMatch(/pattern/), expect(value).toContain('substring')
  • Arrays: expect(array).toContain(item), expect(array).toHaveLength(3)
  • Objects: expect(object).toHaveProperty('key', value)
  • Exceptions: expect(fn).toThrow(), expect(fn).toThrow(Error)
  • Mock functions: expect(mockFn).toHaveBeenCalled(), expect(mockFn).toHaveBeenCalledWith(arg1, arg2)
자주 묻는 질문

'모의 객체(mocks)'란 무엇인가요?

테스트 중에 사용하는 코드 부분(함수나 모듈 등)의 가짜 버전입니다. 이 부분의 동작을 통제하고, 외부나 복잡한 시스템에 의존하지 않고 코드를 테스트할 수 있게 합니다.

테스트를 왜 하나요?

코드가 기대대로 작동하는지 확인하고, 특히 변경할 때 오류를 빨리 잡기 위해서입니다. 코드가 쉽게 깨지지 않을 것이라는 확신을 줍니다.

'스냅샷 테스트'란 무엇인가요?

사용자 인터페이스나 복잡한 데이터 구조를 테스트하는 기법입니다. 예상 출력의 '스냅샷'을 찍어 두고, 이후 테스트에서 현재 출력과 비교해 예상치 못한 변화가 있는지 확인합니다.

상세 정보

작성자의 원본 설명

Best practices for writing JavaScript/TypeScript tests using Jest, including mocking strategies, test structure, and common patterns.

repo: github/awesome-copilot

인기도

GitHub 스타
40k
순위
#7262
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬