ホーム/テスト&QA/javascript-typescript-jest
J

javascript-typescript-jest

by @githubv
4.5(317)

Jestを使用したJavaScript/TypeScriptテストの記述に関するベストプラクティスを提供し、モック戦略、テスト構造、一般的なパターンを含みます。

javascripttypescriptjestunit-testingnodejsGitHub
インストール方法
npx skills add github/awesome-copilot --skill javascript-typescript-jest
compare_arrows

Before / After 効果比較

1
使用前

JavaScript/TypeScriptのテストを作成する際、統一されたJestのベストプラクティスが不足しているため、テストコードの品質が低く、保守が困難でした。テストカバレッジも不十分で、コード品質の保証が難しい状況でした。

使用後

Jestのベストプラクティスに従うことで、テストコードの構造が明確になり、保守が容易で、モック戦略も効率的になりました。これにより、テスト効率とコード品質が大幅に向上し、アプリケーションの安定性が確保されます。

SKILL.md

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)

ユーザーレビュー (0)

レビューを書く

効果
使いやすさ
ドキュメント
互換性

レビューなし

統計データ

インストール数10.6K
評価4.5 / 5.0
バージョン
更新日2026年5月21日
比較事例1 件

ユーザー評価

4.5(317)
5
23%
4
51%
3
23%
2
2%
1
0%

この Skill を評価

0.0

対応プラットフォーム

🔧Claude Code
🔧OpenClaw
🔧OpenCode
🔧Codex
🔧Gemini CLI
🔧GitHub Copilot
🔧Amp
🔧Kimi CLI

タイムライン

作成2026年3月16日
最終更新2026年5月21日