Writing tests is hard. This skill provides proven patterns and examples for unit, integration, and end-to-end testing using Jest, Vitest, and Testing Library so you can build reliable test suites quickly.
スキルZIPをダウンロード
Claudeでアップロード
設定 → 機能 → スキル → スキルをアップロードへ移動
オンにして利用開始
テストする
「javascript-testing-patterns」を使用しています。 Write unit tests for an add function that takes two numbers and returns their sum
期待される結果:
- ```typescript
- import { describe, it, expect } from 'vitest';
- import { add } from './calculator';
- describe('add', () => {
- it('should add two positive numbers', () => {
- expect(add(2, 3)).toBe(5);
- });
- it('should add negative numbers', () => {
- expect(add(-2, -3)).toBe(-5);
- });
- it('should handle zero', () => {
- expect(add(0, 5)).toBe(5);
- });
- });
- ```
「javascript-testing-patterns」を使用しています。 Create a test for a user form component that validates email and submits data
期待される結果:
- ```typescript
- import { render, screen, fireEvent } from '@testing-library/react';
- import { describe, it, expect, vi } from 'vitest';
- import { UserForm } from './UserForm';
- describe('UserForm', () => {
- it('should show validation error for invalid email', () => {
- render(<UserForm onSubmit={vi.fn()} />);
- fireEvent.change(screen.getByTestId('email-input'), {
- target: { value: 'invalid-email' }
- });
- fireEvent.click(screen.getByRole('button', { name: 'Submit' }));
- expect(screen.getByText('Invalid email')).toBeInTheDocument();
- });
- it('should call onSubmit with form data', () => {
- const onSubmit = vi.fn();
- render(<UserForm onSubmit={onSubmit} />);
- fireEvent.change(screen.getByTestId('name-input'), {
- target: { value: 'John Doe' }
- });
- fireEvent.change(screen.getByTestId('email-input'), {
- target: { value: 'john@example.com' }
- });
- fireEvent.click(screen.getByRole('button', { name: 'Submit' }));
- expect(onSubmit).toHaveBeenCalledWith({
- name: 'John Doe',
- email: 'john@example.com'
- });
- });
- });
- ```
セキュリティ監査
安全All 145 static findings are false positives. The detected patterns exist only in code examples within markdown documentation files, not in executable code. The skill provides educational content about testing patterns with code samples demonstrating legitimate testing practices including mock setup, API testing, email service testing, and database integration testing. No executable code, no security risks.
品質スコア
作れるもの
New Project Test Setup
Developers starting a new JavaScript/TypeScript project who need to establish test infrastructure from scratch with proper framework configuration, directory structure, and CI/CD integration.
Add Tests to Existing Codebase
Teams maintaining legacy or untested applications who need to gradually introduce testing for existing functions, APIs, and components without breaking existing functionality.
Improve Test Coverage
Developers seeking to increase code coverage and improve test quality by learning advanced mocking patterns, fixture factories, and integration testing strategies.
これらのプロンプトを試す
Write unit tests for a function that [describe what function does]. Include tests for success cases and error handling.
Create React Testing Library tests for a component that [describe component behavior]. Test user interactions, form submissions, and error states.
Write integration tests for a REST API endpoint that [describe endpoint functionality]. Include database setup, authentication, and cleanup using supertest.
Create tests for [service/class] that mock external dependencies including [list dependencies]. Use dependency injection and vi.mock patterns.
ベストプラクティス
- Follow the Arrange-Act-Assert (AAA) pattern in every test for clear structure and readability
- Test behavior and user interactions rather than implementation details to make tests resilient to refactoring
- Use beforeEach and afterEach hooks for setup and teardown to keep tests isolated and prevent pollution
回避
- Testing implementation details like internal function calls or component state instead of observable behavior
- Writing brittle tests that break when code is refactored but behavior remains unchanged
- Creating overly complex test setups with too many mocks that make tests hard to understand and maintain
よくある質問
Should I use Jest or Vitest?
How do I test code that uses external APIs?
What test coverage should I aim for?
Should I test private methods?
How do I handle database tests?
What is the difference between unit and integration tests?
開発者の詳細
作成者
sickn33ライセンス
MIT
リポジトリ
https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/javascript-testing-patterns参照
main
ファイル構成