[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EM6VMM8WVXTP0PDQ6EGTB4":3,"skill-same:01M6EM6VMM8WVXTP0PDQ6EGTB4":74},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":46,"commitSha":47,"skillDirectory":48,"forksCount":49,"repositoryHtmlUrl":50,"repositoryHomepageUrl":51,"ownerHtmlUrl":52,"ownerBlogUrl":6,"ownerDescription":53,"updatedAt":54,"install":55,"resources":67},"01M6EM6VMM8WVXTP0PDQ6EGTB4","testing-strategy",null,"Comprehensive testing strategy using Vitest for unit\u002Fintegration tests and Playwright for E2E tests with best practices and coverage targets","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fatman36\u002Ftesting-strategy\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],"testing strategy","strategy","testing","quality","targets","unit","tests","vibe","prompts","coverage","vitest","e2e","integration","best practices","e2e tests","integration tests","playwright","tdd","2026-11-10 10:12:30",false,"---\nname: testing-strategy\ndescription: Comprehensive testing strategy using Vitest for unit\u002Fintegration tests and Playwright for E2E tests with best practices and coverage targets\nversion: 1.0.0\nauthor: AI-Vibe-Prompts\ntags: [testing, vitest, playwright, quality, tdd, e2e]\nauto_invoke: true\n---\n\n# Testing Strategy Skill\n\n## Objective\n\nImplement comprehensive testing strategy covering unit, integration, and E2E tests using modern tools (Vitest, Playwright) with clear coverage targets and best practices.\n\n## When to Use This Skill\n\nAuto-invoke when:\n- User mentions \"test\", \"testing\", \"coverage\", \"TDD\", \"E2E\"\n- Setting up new project\n- Adding new features (need tests)\n- Debugging test failures\n- Improving test coverage\n\n## Testing Pyramid\n\n```\n        \u002F\\\n       \u002FE2E\\         Few, slow, expensive\n      \u002F------\\\n     \u002F  Integ \\      Some, moderate speed\n    \u002F----------\\\n   \u002F Unit Tests \\    Many, fast, cheap\n  \u002F--------------\\\n```\n\n**Distribution**:\n- **70%** Unit Tests - Fast, isolated, cheap\n- **20%** Integration Tests - Moderate speed, test interactions\n- **10%** E2E Tests - Slow, expensive, critical user flows\n\n## Test Types\n\n### 1. Unit Tests (Vitest)\n\n**What**: Test individual functions\u002Fcomponents in isolation\n\n**Tools**: Vitest, React Testing Library\n\n**Coverage Target**: 80%+\n\n**Setup**:\n```bash\nnpm install -D vitest @vitest\u002Fui @testing-library\u002Freact @testing-library\u002Fjest-dom\n```\n\n**Config** (`vitest.config.ts`):\n```typescript\nimport { defineConfig } from 'vitest\u002Fconfig'\nimport react from '@vitejs\u002Fplugin-react'\n\nexport default defineConfig({\n  plugins: [react()],\n  test: {\n    globals: true,\n    environment: 'jsdom',\n    setupFiles: '.\u002Ftests\u002Fsetup.ts',\n    coverage: {\n      provider: 'v8',\n      reporter: ['text', 'json', 'html'],\n      exclude: ['node_modules\u002F', 'tests\u002F'],\n      thresholds: {\n        lines: 80,\n        functions: 80,\n        branches: 75,\n        statements: 80\n      }\n    }\n  }\n})\n```\n\n**Example** (`Button.test.tsx`):\n```typescript\nimport { render, screen, fireEvent } from '@testing-library\u002Freact'\nimport { describe, it, expect, vi } from 'vitest'\nimport { Button } from '.\u002FButton'\n\ndescribe('Button', () => {\n  it('renders with text', () => {\n    render(\u003CButton>Click me\u003C\u002FButton>)\n    expect(screen.getByText('Click me')).toBeInTheDocument()\n  })\n\n  it('calls onClick when clicked', () => {\n    const handleClick = vi.fn()\n    render(\u003CButton onClick={handleClick}>Click\u003C\u002FButton>)\n    fireEvent.click(screen.getByText('Click'))\n    expect(handleClick).toHaveBeenCalledOnce()\n  })\n\n  it('is disabled when disabled prop is true', () => {\n    render(\u003CButton disabled>Disabled\u003C\u002FButton>)\n    expect(screen.getByRole('button')).toBeDisabled()\n  })\n})\n```\n\n**Commands**:\n```bash\nnpm run test              # Run all tests\nnpm run test:watch        # Watch mode\nnpm run test:ui           # Visual UI\nnpm run test:coverage     # With coverage\n```\n\n### 2. Integration Tests (Vitest)\n\n**What**: Test component interactions, API calls, state management\n\n**Example** (`UserProfile.test.tsx`):\n```typescript\nimport { render, screen, waitFor } from '@testing-library\u002Freact'\nimport { describe, it, expect, vi } from 'vitest'\nimport { UserProfile } from '.\u002FUserProfile'\n\n\u002F\u002F Mock API\nvi.mock('.\u002Fapi', () => ({\n  fetchUser: vi.fn(() => Promise.resolve({\n    id: 1,\n    name: 'John Doe',\n    email: 'john@example.com'\n  }))\n}))\n\ndescribe('UserProfile Integration', () => {\n  it('fetches and displays user data', async () => {\n    render(\u003CUserProfile userId=\"1\" \u002F>)\n    \n    expect(screen.getByText('Loading...')).toBeInTheDocument()\n    \n    await waitFor(() => {\n      expect(screen.getByText('John Doe')).toBeInTheDocument()\n      expect(screen.getByText('john@example.com')).toBeInTheDocument()\n    })\n  })\n})\n```\n\n### 3. E2E Tests (Playwright)\n\n**What**: Test complete user flows in real browser\n\n**Tools**: Playwright\n\n**Coverage Target**: Critical paths only\n\n**Setup**:\n```bash\nnpm install -D @playwright\u002Ftest\nnpx playwright install\n```\n\n**Config** (`playwright.config.ts`):\n```typescript\nimport { defineConfig, devices } from '@playwright\u002Ftest'\n\nexport default defineConfig({\n  testDir: '.\u002Fe2e',\n  fullyParallel: true,\n  forbidOnly: !!process.env.CI,\n  retries: process.env.CI ? 2 : 0,\n  workers: process.env.CI ? 1 : undefined,\n  reporter: 'html',\n  use: {\n    baseURL: 'http:\u002F\u002Flocalhost:3000',\n    trace: 'on-first-retry',\n  },\n  projects: [\n    {\n      name: 'chromium',\n      use: { ...devices['Desktop Chrome'] },\n    },\n    {\n      name: 'mobile',\n      use: { ...devices['iPhone 13'] },\n    },\n  ],\n  webServer: {\n    command: 'npm run dev',\n    url: 'http:\u002F\u002Flocalhost:3000',\n    reuseExistingServer: !process.env.CI,\n  },\n})\n```\n\n**Example** (`e2e\u002Fauth.spec.ts`):\n```typescript\nimport { test, expect } from '@playwright\u002Ftest'\n\ntest.describe('Authentication Flow', () => {\n  test('user can sign up and log in', async ({ page }) => {\n    \u002F\u002F Sign up\n    await page.goto('\u002Fsignup')\n    await page.fill('[name=\"email\"]', 'test@example.com')\n    await page.fill('[name=\"password\"]', 'SecurePass123!')\n    await page.click('button[type=\"submit\"]')\n    \n    \u002F\u002F Should redirect to dashboard\n    await expect(page).toHaveURL(\u002F\\\u002Fdashboard\u002F)\n    await expect(page.locator('h1')).toContainText('Welcome')\n    \n    \u002F\u002F Log out\n    await page.click('[aria-label=\"User menu\"]')\n    await page.click('text=Logout')\n    \n    \u002F\u002F Should redirect to home\n    await expect(page).toHaveURL('\u002F')\n    \n    \u002F\u002F Log back in\n    await page.goto('\u002Flogin')\n    await page.fill('[name=\"email\"]', 'test@example.com')\n    await page.fill('[name=\"password\"]', 'SecurePass123!')\n    await page.click('button[type=\"submit\"]')\n    \n    await expect(page).toHaveURL(\u002F\\\u002Fdashboard\u002F)\n  })\n})\n```\n\n**Commands**:\n```bash\nnpx playwright test                    # Run all E2E\nnpx playwright test --ui               # Interactive mode\nnpx playwright test --headed           # Show browser\nnpx playwright test --project=chromium # Specific browser\nnpx playwright show-report             # View last report\n```\n\n## Testing Best Practices\n\n### AAA Pattern\n```typescript\n\u002F\u002F Arrange\nconst user = { id: 1, name: 'John' }\nconst mockFetch = vi.fn()\n\n\u002F\u002F Act\nconst result = await fetchUser(mockFetch, 1)\n\n\u002F\u002F Assert\nexpect(result).toEqual(user)\nexpect(mockFetch).toHaveBeenCalledWith('\u002Fapi\u002Fusers\u002F1')\n```\n\n### Test Naming\n```typescript\n\u002F\u002F Good: descriptive, explains what and when\nit('displays error message when API returns 404', () => {})\nit('disables submit button when form is invalid', () => {})\n\n\u002F\u002F Bad: vague, unclear\nit('works', () => {})\nit('test 1', () => {})\n```\n\n### One Assertion Per Test (Guideline)\n```typescript\n\u002F\u002F Prefer focused tests\nit('renders user name', () => {\n  render(\u003CUser name=\"John\" \u002F>)\n  expect(screen.getByText('John')).toBeInTheDocument()\n})\n\nit('renders user email', () => {\n  render(\u003CUser email=\"john@example.com\" \u002F>)\n  expect(screen.getByText('john@example.com')).toBeInTheDocument()\n})\n\n\u002F\u002F Over complex tests\nit('renders user data', () => {\n  \u002F\u002F Multiple unrelated assertions\n})\n```\n\n### Mock External Dependencies\n```typescript\n\u002F\u002F Mock API calls\nvi.mock('.\u002Fapi', () => ({\n  fetchUser: vi.fn()\n}))\n\n\u002F\u002F Mock environment\nvi.stubEnv('API_URL', 'http:\u002F\u002Ftest-api.com')\n\n\u002F\u002F Mock timers\nvi.useFakeTimers()\nconst now = new Date('2024-01-01')\nvi.setSystemTime(now)\n```\n\n## Coverage Strategy\n\n### What to Test\n\n✅ **Do Test**:\n- Business logic\n- Edge cases and error handling\n- User interactions\n- API integration\n- State management\n- Validation logic\n- Critical user flows (E2E)\n\n❌ **Don't Test**:\n- Third-party libraries\n- Framework internals\n- Constants\n- Simple getters\u002Fsetters\n- Generated code\n\n### Coverage Targets\n\n**Minimum**:\n- Lines: 80%\n- Functions: 80%\n- Branches: 75%\n- Statements: 80%\n\n**Ideal**:\n- Critical paths: 100%\n- Business logic: 95%+\n- UI components: 85%+\n- Utilities: 90%+\n\n### Run Coverage\n```bash\nnpm run test:coverage\n\n# View in browser\nopen coverage\u002Findex.html\n```\n\n## Testing Workflow\n\n### 1. TDD Approach (Recommended)\n```\n1. Write failing test\n2. Write minimal code to pass\n3. Refactor\n4. Repeat\n```\n\n### 2. Test-After (Pragmatic)\n```\n1. Implement feature\n2. Write tests\n3. Achieve 80%+ coverage\n4. Refactor with confidence\n```\n\n### 3. Pre-Commit Testing\n```bash\n# Run before every commit\nnpm run test:quick        # Fast unit tests\nnpm run lint\nnpm run typecheck\n\n# Run before push\nnpm run test             # All unit\u002Fintegration\nnpm run test:coverage    # Verify coverage\n\n# Run before deploy\nnpm run test:e2e         # Full E2E suite\n```\n\n## Test Organization\n\n### Directory Structure\n```\nsrc\u002F\n├── components\u002F\n│   ├── Button\u002F\n│   │   ├── Button.tsx\n│   │   ├── Button.test.tsx      # Co-located\n│   │   └── Button.stories.tsx   # Storybook\n│   └── ...\ntests\u002F\n├── setup.ts                      # Test setup\n├── utils\u002F                        # Test utilities\n│   ├── renderWithProviders.tsx  # Custom render\n│   └── mockData.ts              # Test fixtures\n└── __mocks__\u002F                   # Global mocks\ne2e\u002F\n├── auth.spec.ts\n├── checkout.spec.ts\n└── fixtures\u002F                    # E2E test data\n```\n\n### Naming Conventions\n- Unit\u002FIntegration: `*.test.ts` or `*.test.tsx`\n- E2E: `*.spec.ts`\n- Setup: `setup.ts`, `vitest.config.ts`\n\n## Continuous Integration\n\n### GitHub Actions Example\n```yaml\nname: Tests\non: [push, pull_request]\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v3\n      - uses: actions\u002Fsetup-node@v3\n        with:\n          node-version: 18\n          cache: 'npm'\n      \n      - run: npm ci\n      - run: npm run lint\n      - run: npm run typecheck\n      - run: npm run test:coverage\n      \n      - name: Upload coverage\n        uses: codecov\u002Fcodecov-action@v3\n        with:\n          files: .\u002Fcoverage\u002Fcoverage-final.json\n  \n  e2e:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v3\n      - uses: actions\u002Fsetup-node@v3\n      - run: npm ci\n      - run: npx playwright install --with-deps\n      - run: npm run build\n      - run: npx playwright test\n      \n      - uses: actions\u002Fupload-artifact@v3\n        if: always()\n        with:\n          name: playwright-report\n          path: playwright-report\u002F\n```\n\n## Debugging Tests\n\n### Vitest\n```bash\n# Run single test file\nnpm run test -- Button.test.tsx\n\n# Run tests matching pattern\nnpm run test -- --grep \"Button renders\"\n\n# Debug in VS Code\n# Add breakpoint, press F5\n```\n\n### Playwright\n```bash\n# Debug mode\nnpx playwright test --debug\n\n# Specific test\nnpx playwright test auth.spec.ts --debug\n\n# Trace viewer\nnpx playwright show-trace trace.zip\n```\n\n## Common Testing Patterns\n\n### Testing Async Code\n```typescript\nit('fetches user data', async () => {\n  const { result } = renderHook(() => useUser(1))\n  \n  await waitFor(() => {\n    expect(result.current.data).toEqual({ id: 1, name: 'John' })\n  })\n})\n```\n\n### Testing Error States\n```typescript\nit('displays error when fetch fails', async () => {\n  vi.mocked(fetchUser).mockRejectedValue(new Error('Network error'))\n  \n  render(\u003CUserProfile userId=\"1\" \u002F>)\n  \n  await waitFor(() => {\n    expect(screen.getByText(\u002Ferror\u002Fi)).toBeInTheDocument()\n  })\n})\n```\n\n### Testing Forms\n```typescript\nit('submits form with valid data', async () => {\n  const handleSubmit = vi.fn()\n  render(\u003CLoginForm onSubmit={handleSubmit} \u002F>)\n  \n  await userEvent.type(screen.getByLabelText('Email'), 'test@example.com')\n  await userEvent.type(screen.getByLabelText('Password'), 'password123')\n  await userEvent.click(screen.getByRole('button', { name: \u002Fsubmit\u002Fi }))\n  \n  expect(handleSubmit).toHaveBeenCalledWith({\n    email: 'test@example.com',\n    password: 'password123'\n  })\n})\n```\n\n## Integration with Other Skills\n\n- `quality-gates` - Run tests as quality check\n- `git-workflow` - Tests in pre-commit hooks\n- `codebase-analysis` - Identify untested code\n\n## Package.json Scripts\n\n```json\n{\n  \"scripts\": {\n    \"test\": \"vitest\",\n    \"test:watch\": \"vitest --watch\",\n    \"test:ui\": \"vitest --ui\",\n    \"test:coverage\": \"vitest --coverage\",\n    \"test:e2e\": \"playwright test\",\n    \"test:e2e:ui\": \"playwright test --ui\",\n    \"test:e2e:headed\": \"playwright test --headed\",\n    \"test:all\": \"npm run test:coverage && npm run test:e2e\"\n  }\n}\n```\n\n## Version History\n\n- **1.0.0** (2025-01-03): Initial testing strategy with Vitest and Playwright\n","# Testing Strategy Skill\n\n## Objective\n\nImplement comprehensive testing strategy covering unit, integration, and E2E tests using modern tools (Vitest, Playwright) with clear coverage targets and best practices.\n\n## When to Use This Skill\n\nAuto-invoke when:\n- User mentions \"test\", \"testing\", \"coverage\", \"TDD\", \"E2E\"\n- Setting up new project\n- Adding new features (need tests)\n- Debugging test failures\n- Improving test coverage\n\n## Testing Pyramid\n\n```\n        \u002F\\\n       \u002FE2E\\         Few, slow, expensive\n      \u002F------\\\n     \u002F  Integ \\      Some, moderate speed\n    \u002F----------\\\n   \u002F Unit Tests \\    Many, fast, cheap\n  \u002F--------------\\\n```\n\n**Distribution**:\n- **70%** Unit Tests - Fast, isolated, cheap\n- **20%** Integration Tests - Moderate speed, test interactions\n- **10%** E2E Tests - Slow, expensive, critical user flows\n\n## Test Types\n\n### 1. Unit Tests (Vitest)\n\n**What**: Test individual functions\u002Fcomponents in isolation\n\n**Tools**: Vitest, React Testing Library\n\n**Coverage Target**: 80%+\n\n**Setup**:\n```bash\nnpm install -D vitest @vitest\u002Fui @testing-library\u002Freact @testing-library\u002Fjest-dom\n```\n\n**Config** (`vitest.config.ts`):\n```typescript\nimport { defineConfig } from 'vitest\u002Fconfig'\nimport react from '@vitejs\u002Fplugin-react'\n\nexport default defineConfig({\n  plugins: [react()],\n  test: {\n    globals: true,\n    environment: 'jsdom',\n    setupFiles: '.\u002Ftests\u002Fsetup.ts',\n    coverage: {\n      provider: 'v8',\n      reporter: ['text', 'json', 'html'],\n      exclude: ['node_modules\u002F', 'tests\u002F'],\n      thresholds: {\n        lines: 80,\n        functions: 80,\n        branches: 75,\n        statements: 80\n      }\n    }\n  }\n})\n```\n\n**Example** (`Button.test.tsx`):\n```typescript\nimport { render, screen, fireEvent } from '@testing-library\u002Freact'\nimport { describe, it, expect, vi } from 'vitest'\nimport { Button } from '.\u002FButton'\n\ndescribe('Button', () => {\n  it('renders with text', () => {\n    render(\u003CButton>Click me\u003C\u002FButton>)\n    expect(screen.getByText('Click me')).toBeInTheDocument()\n  })\n\n  it('calls onClick when clicked', () => {\n    const handleClick = vi.fn()\n    render(\u003CButton onClick={handleClick}>Click\u003C\u002FButton>)\n    fireEvent.click(screen.getByText('Click'))\n    expect(handleClick).toHaveBeenCalledOnce()\n  })\n\n  it('is disabled when disabled prop is true', () => {\n    render(\u003CButton disabled>Disabled\u003C\u002FButton>)\n    expect(screen.getByRole('button')).toBeDisabled()\n  })\n})\n```\n\n**Commands**:\n```bash\nnpm run test              # Run all tests\nnpm run test:watch        # Watch mode\nnpm run test:ui           # Visual UI\nnpm run test:coverage     # With coverage\n```\n\n### 2. Integration Tests (Vitest)\n\n**What**: Test component interactions, API calls, state management\n\n**Example** (`UserProfile.test.tsx`):\n```typescript\nimport { render, screen, waitFor } from '@testing-library\u002Freact'\nimport { describe, it, expect, vi } from 'vitest'\nimport { UserProfile } from '.\u002FUserProfile'\n\n\u002F\u002F Mock API\nvi.mock('.\u002Fapi', () => ({\n  fetchUser: vi.fn(() => Promise.resolve({\n    id: 1,\n    name: 'John Doe',\n    email: 'john@example.com'\n  }))\n}))\n\ndescribe('UserProfile Integration', () => {\n  it('fetches and displays user data', async () => {\n    render(\u003CUserProfile userId=\"1\" \u002F>)\n    \n    expect(screen.getByText('Loading...')).toBeInTheDocument()\n    \n    await waitFor(() => {\n      expect(screen.getByText('John Doe')).toBeInTheDocument()\n      expect(screen.getByText('john@example.com')).toBeInTheDocument()\n    })\n  })\n})\n```\n\n### 3. E2E Tests (Playwright)\n\n**What**: Test complete user flows in real browser\n\n**Tools**: Playwright\n\n**Coverage Target**: Critical paths only\n\n**Setup**:\n```bash\nnpm install -D @playwright\u002Ftest\nnpx playwright install\n```\n\n**Config** (`playwright.config.ts`):\n```typescript\nimport { defineConfig, devices } from '@playwright\u002Ftest'\n\nexport default defineConfig({\n  testDir: '.\u002Fe2e',\n  fullyParallel: true,\n  forbidOnly: !!process.env.CI,\n  retries: process.env.CI ? 2 : 0,\n  workers: process.env.CI ? 1 : undefined,\n  reporter: 'html',\n  use: {\n    baseURL: 'http:\u002F\u002Flocalhost:3000',\n    trace: 'on-first-retry',\n  },\n  projects: [\n    {\n      name: 'chromium',\n      use: { ...devices['Desktop Chrome'] },\n    },\n    {\n      name: 'mobile',\n      use: { ...devices['iPhone 13'] },\n    },\n  ],\n  webServer: {\n    command: 'npm run dev',\n    url: 'http:\u002F\u002Flocalhost:3000',\n    reuseExistingServer: !process.env.CI,\n  },\n})\n```\n\n**Example** (`e2e\u002Fauth.spec.ts`):\n```typescript\nimport { test, expect } from '@playwright\u002Ftest'\n\ntest.describe('Authentication Flow', () => {\n  test('user can sign up and log in', async ({ page }) => {\n    \u002F\u002F Sign up\n    await page.goto('\u002Fsignup')\n    await page.fill('[name=\"email\"]', 'test@example.com')\n    await page.fill('[name=\"password\"]', 'SecurePass123!')\n    await page.click('button[type=\"submit\"]')\n    \n    \u002F\u002F Should redirect to dashboard\n    await expect(page).toHaveURL(\u002F\\\u002Fdashboard\u002F)\n    await expect(page.locator('h1')).toContainText('Welcome')\n    \n    \u002F\u002F Log out\n    await page.click('[aria-label=\"User menu\"]')\n    await page.click('text=Logout')\n    \n    \u002F\u002F Should redirect to home\n    await expect(page).toHaveURL('\u002F')\n    \n    \u002F\u002F Log back in\n    await page.goto('\u002Flogin')\n    await page.fill('[name=\"email\"]', 'test@example.com')\n    await page.fill('[name=\"password\"]', 'SecurePass123!')\n    await page.click('button[type=\"submit\"]')\n    \n    await expect(page).toHaveURL(\u002F\\\u002Fdashboard\u002F)\n  })\n})\n```\n\n**Commands**:\n```bash\nnpx playwright test                    # Run all E2E\nnpx playwright test --ui               # Interactive mode\nnpx playwright test --headed           # Show browser\nnpx playwright test --project=chromium # Specific browser\nnpx playwright show-report             # View last report\n```\n\n## Testing Best Practices\n\n### AAA Pattern\n```typescript\n\u002F\u002F Arrange\nconst user = { id: 1, name: 'John' }\nconst mockFetch = vi.fn()\n\n\u002F\u002F Act\nconst result = await fetchUser(mockFetch, 1)\n\n\u002F\u002F Assert\nexpect(result).toEqual(user)\nexpect(mockFetch).toHaveBeenCalledWith('\u002Fapi\u002Fusers\u002F1')\n```\n\n### Test Naming\n```typescript\n\u002F\u002F Good: descriptive, explains what and when\nit('displays error message when API returns 404', () => {})\nit('disables submit button when form is invalid', () => {})\n\n\u002F\u002F Bad: vague, unclear\nit('works', () => {})\nit('test 1', () => {})\n```\n\n### One Assertion Per Test (Guideline)\n```typescript\n\u002F\u002F Prefer focused tests\nit('renders user name', () => {\n  render(\u003CUser name=\"John\" \u002F>)\n  expect(screen.getByText('John')).toBeInTheDocument()\n})\n\nit('renders user email', () => {\n  render(\u003CUser email=\"john@example.com\" \u002F>)\n  expect(screen.getByText('john@example.com')).toBeInTheDocument()\n})\n\n\u002F\u002F Over complex tests\nit('renders user data', () => {\n  \u002F\u002F Multiple unrelated assertions\n})\n```\n\n### Mock External Dependencies\n```typescript\n\u002F\u002F Mock API calls\nvi.mock('.\u002Fapi', () => ({\n  fetchUser: vi.fn()\n}))\n\n\u002F\u002F Mock environment\nvi.stubEnv('API_URL', 'http:\u002F\u002Ftest-api.com')\n\n\u002F\u002F Mock timers\nvi.useFakeTimers()\nconst now = new Date('2024-01-01')\nvi.setSystemTime(now)\n```\n\n## Coverage Strategy\n\n### What to Test\n\n✅ **Do Test**:\n- Business logic\n- Edge cases and error handling\n- User interactions\n- API integration\n- State management\n- Validation logic\n- Critical user flows (E2E)\n\n❌ **Don't Test**:\n- Third-party libraries\n- Framework internals\n- Constants\n- Simple getters\u002Fsetters\n- Generated code\n\n### Coverage Targets\n\n**Minimum**:\n- Lines: 80%\n- Functions: 80%\n- Branches: 75%\n- Statements: 80%\n\n**Ideal**:\n- Critical paths: 100%\n- Business logic: 95%+\n- UI components: 85%+\n- Utilities: 90%+\n\n### Run Coverage\n```bash\nnpm run test:coverage\n\n# View in browser\nopen coverage\u002Findex.html\n```\n\n## Testing Workflow\n\n### 1. TDD Approach (Recommended)\n```\n1. Write failing test\n2. Write minimal code to pass\n3. Refactor\n4. Repeat\n```\n\n### 2. Test-After (Pragmatic)\n```\n1. Implement feature\n2. Write tests\n3. Achieve 80%+ coverage\n4. Refactor with confidence\n```\n\n### 3. Pre-Commit Testing\n```bash\n# Run before every commit\nnpm run test:quick        # Fast unit tests\nnpm run lint\nnpm run typecheck\n\n# Run before push\nnpm run test             # All unit\u002Fintegration\nnpm run test:coverage    # Verify coverage\n\n# Run before deploy\nnpm run test:e2e         # Full E2E suite\n```\n\n## Test Organization\n\n### Directory Structure\n```\nsrc\u002F\n├── components\u002F\n│   ├── Button\u002F\n│   │   ├── Button.tsx\n│   │   ├── Button.test.tsx      # Co-located\n│   │   └── Button.stories.tsx   # Storybook\n│   └── ...\ntests\u002F\n├── setup.ts                      # Test setup\n├── utils\u002F                        # Test utilities\n│   ├── renderWithProviders.tsx  # Custom render\n│   └── mockData.ts              # Test fixtures\n└── __mocks__\u002F                   # Global mocks\ne2e\u002F\n├── auth.spec.ts\n├── checkout.spec.ts\n└── fixtures\u002F                    # E2E test data\n```\n\n### Naming Conventions\n- Unit\u002FIntegration: `*.test.ts` or `*.test.tsx`\n- E2E: `*.spec.ts`\n- Setup: `setup.ts`, `vitest.config.ts`\n\n## Continuous Integration\n\n### GitHub Actions Example\n```yaml\nname: Tests\non: [push, pull_request]\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v3\n      - uses: actions\u002Fsetup-node@v3\n        with:\n          node-version: 18\n          cache: 'npm'\n      \n      - run: npm ci\n      - run: npm run lint\n      - run: npm run typecheck\n      - run: npm run test:coverage\n      \n      - name: Upload coverage\n        uses: codecov\u002Fcodecov-action@v3\n        with:\n          files: .\u002Fcoverage\u002Fcoverage-final.json\n  \n  e2e:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v3\n      - uses: actions\u002Fsetup-node@v3\n      - run: npm ci\n      - run: npx playwright install --with-deps\n      - run: npm run build\n      - run: npx playwright test\n      \n      - uses: actions\u002Fupload-artifact@v3\n        if: always()\n        with:\n          name: playwright-report\n          path: playwright-report\u002F\n```\n\n## Debugging Tests\n\n### Vitest\n```bash\n# Run single test file\nnpm run test -- Button.test.tsx\n\n# Run tests matching pattern\nnpm run test -- --grep \"Button renders\"\n\n# Debug in VS Code\n# Add breakpoint, press F5\n```\n\n### Playwright\n```bash\n# Debug mode\nnpx playwright test --debug\n\n# Specific test\nnpx playwright test auth.spec.ts --debug\n\n# Trace viewer\nnpx playwright show-trace trace.zip\n```\n\n## Common Testing Patterns\n\n### Testing Async Code\n```typescript\nit('fetches user data', async () => {\n  const { result } = renderHook(() => useUser(1))\n  \n  await waitFor(() => {\n    expect(result.current.data).toEqual({ id: 1, name: 'John' })\n  })\n})\n```\n\n### Testing Error States\n```typescript\nit('displays error when fetch fails', async () => {\n  vi.mocked(fetchUser).mockRejectedValue(new Error('Network error'))\n  \n  render(\u003CUserProfile userId=\"1\" \u002F>)\n  \n  await waitFor(() => {\n    expect(screen.getByText(\u002Ferror\u002Fi)).toBeInTheDocument()\n  })\n})\n```\n\n### Testing Forms\n```typescript\nit('submits form with valid data', async () => {\n  const handleSubmit = vi.fn()\n  render(\u003CLoginForm onSubmit={handleSubmit} \u002F>)\n  \n  await userEvent.type(screen.getByLabelText('Email'), 'test@example.com')\n  await userEvent.type(screen.getByLabelText('Password'), 'password123')\n  await userEvent.click(screen.getByRole('button', { name: \u002Fsubmit\u002Fi }))\n  \n  expect(handleSubmit).toHaveBeenCalledWith({\n    email: 'test@example.com',\n    password: 'password123'\n  })\n})\n```\n\n## Integration with Other Skills\n\n- `quality-gates` - Run tests as quality check\n- `git-workflow` - Tests in pre-commit hooks\n- `codebase-analysis` - Identify untested code\n\n## Package.json Scripts\n\n```json\n{\n  \"scripts\": {\n    \"test\": \"vitest\",\n    \"test:watch\": \"vitest --watch\",\n    \"test:ui\": \"vitest --ui\",\n    \"test:coverage\": \"vitest --coverage\",\n    \"test:e2e\": \"playwright test\",\n    \"test:e2e:ui\": \"playwright test --ui\",\n    \"test:e2e:headed\": \"playwright test --headed\",\n    \"test:all\": \"npm run test:coverage && npm run test:e2e\"\n  }\n}\n```\n\n## Version History\n\n- **1.0.0** (2025-01-03): Initial testing strategy with Vitest and Playwright\n",{"name":5,"tags":42,"author":43,"version":44,"auto_invoke":45,"description":7},[21,29,35,22,36,30],"AI-Vibe-Prompts","1.0.0",true,"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002Fatman36\u002Ftesting-strategy",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":56,"prompt":66,"zipAvailable":45},[57,60,63],{"tool":58,"command":59},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill testing-strategy",{"tool":61,"command":62},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill testing-strategy",{"tool":64,"command":65},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill testing-strategy","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fatman36\u002Ftesting-strategy\u002FSKILL.md",[68],{"path":69,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":73},"skill-report.json","REFERENCE","参考文档",17795,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fatman36\u002Ftesting-strategy\u002Fskill-report.json",[75,84,93,102,108,114],{"skillNo":76,"name":77,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":37},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[81,82,83],"model","model hierarchy","model hierarchy skill",{"skillNo":85,"name":86,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":37},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[90,91,92],"MCP","zoom","zoom mcp",{"skillNo":94,"name":95,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":37},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[99,100,101,91],"sdk","zoom apps sdk","apps",{"skillNo":103,"name":104,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":37},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[104],{"skillNo":109,"name":110,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":37},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[110],{"skillNo":115,"name":116,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":117,"categories":118,"keywords":119,"publishedAt":37},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[116]]