[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EKCPAS3BDDTPZP8GZE4CR8":3,"skill-same:01M7EKCPAS3BDDTPZP8GZE4CR8":54},{"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":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":14,"repositoryHtmlUrl":29,"repositoryHomepageUrl":6,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M7EKCPAS3BDDTPZP8GZE4CR8","testing",null,"Guides writing, reviewing, and debugging Vitest tests for JavaScript and TypeScript projects, covering test structure, async handling, mocking, error cases, setup and teardown, and a review checklist of common anti-patterns. Use when writing new tests, reviewing a test file, or debugging a failing or flaky Vitest suite. Not for Python test suites.","razorvision\u002Fclara-skills","razorvision","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F11950812?v=4","01M7EKAE3CT4VN0CGC4GR8ZFAP","Razorvision Consulting","01M7EKAE3Z8WT4D2X0K2488E9V",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills\u002Fblob\u002Fmain\u002Fskills\u002Ftesting\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: testing\ndescription: Guides writing, reviewing, and debugging Vitest tests for JavaScript and TypeScript projects, covering test structure, async handling, mocking, error cases, setup and teardown, and a review checklist of common anti-patterns. Use when writing new tests, reviewing a test file, or debugging a failing or flaky Vitest suite. Not for Python test suites.\nlicense: Apache-2.0\nmetadata:\n  version: \"0.1.0\" # x-release-please-version\n  owner: razorvision\n---\n\n# Testing Skill\n\nApply this skill when writing, reviewing, or debugging tests.\n\n## Test Configuration\n\nRead the project's `vitest.config.*` (or the `test` block in `vite.config.*`) before writing\ntests, and match it. Typical settings to check:\n- **Environment:** `node` for server\u002Flibrary code, `jsdom` or `happy-dom` for DOM code\n- **Timeout:** raised (e.g. 30 seconds) for API\u002Fintegration tests\n- **Pattern:** where tests live, e.g. `src\u002F**\u002F*.test.ts` or colocated `*.test.ts`\n- **Env vars:** how test env vars are loaded (e.g. from an env file or a setup file)\n- **Path alias:** if the project uses path aliases (e.g. `@\u002F` mapping to `.\u002Fsrc\u002F`), use them in\n  imports and mocks exactly as the source code does\n\n## Core Patterns\n\n### 1. Test File Structure\n\n```typescript\nimport { describe, it, expect, beforeEach, vi } from 'vitest'\n\ndescribe('ModuleName', () => {\n  describe('functionName', () => {\n    it('returns expected result when given valid input', async () => {\n      \u002F\u002F Arrange\n      const input = { ... }\n\n      \u002F\u002F Act\n      const result = await functionName(input)\n\n      \u002F\u002F Assert\n      expect(result).toEqual(expected)\n    })\n\n    it('throws error when given invalid input', async () => {\n      await expect(functionName(null)).rejects.toThrow('Expected error')\n    })\n  })\n})\n```\n\n### 2. Async Tests\n\nAlways use `async\u002Fawait` for async operations:\n\n```typescript\n\u002F\u002F Correct\nit('fetches data from API', async () => {\n  const result = await fetchData()\n  expect(result).toBeDefined()\n})\n\n\u002F\u002F Wrong - missing await\nit('fetches data from API', () => {\n  const result = fetchData()  \u002F\u002F Promise, not result!\n  expect(result).toBeDefined()\n})\n```\n\n### 3. Specific and Realistic Assertions\n\nFor pure functions, assert exact values. For integration tests against live or variable data,\nuse range- and shape-based assertions:\n\n```typescript\n\u002F\u002F Pure function: exact values\nit('applies a percentage discount and rounds to cents', () => {\n  expect(applyDiscount(19.99, 0.15)).toBe(16.99)\n  expect(applyDiscount(100, 0)).toBe(100)\n})\n\n\u002F\u002F Integration: realistic ranges and shapes\nit('returns a plausible exchange rate', async () => {\n  const result = await getExchangeRate('USD', 'EUR')\n\n  \u002F\u002F Rate should be in a realistic range\n  expect(result.rate).toBeGreaterThan(0.5)\n  expect(result.rate).toBeLessThan(2)\n\n  \u002F\u002F Pair should match the request\n  expect(result.pair).toMatch(\u002FUSD\\\u002FEUR\u002F)\n\n  \u002F\u002F Required fields present\n  expect(result.source).toBeTruthy()\n  expect(result.fetchedAt).toBeInstanceOf(Date)\n})\n```\n\n### 4. Mocking an API Client Module\n\n```typescript\nimport { vi } from 'vitest'\n\n\u002F\u002F Mock the whole module (path must match the import used in the code under test)\nvi.mock('.\u002Flib\u002Fapi-client', () => ({\n  apiClient: {\n    get: vi.fn().mockResolvedValue({ data: mockData, error: null }),\n    post: vi.fn().mockResolvedValue({ data: { id: '123' }, error: null }),\n  },\n}))\n\n\u002F\u002F Or build a chainable query-builder mock for fluent SDKs\nconst mockDb = {\n  from: vi.fn().mockReturnValue({\n    select: vi.fn().mockReturnValue({\n      eq: vi.fn().mockResolvedValue({ data: [], error: null }),\n    }),\n  }),\n}\n```\n\n### 5. Test Organization\n\nGroup related tests with nested `describe`:\n\n```typescript\ndescribe('PaymentProvider', () => {\n  describe('Card payments', () => {\n    describe('charge', () => {\n      it('charges the exact amount in minor units', async () => { ... })\n      it('handles a declined card gracefully', async () => { ... })\n      it('retries once on a transient network error', async () => { ... })\n    })\n  })\n\n  describe('Bank transfers', () => {\n    describe('buildReference', () => {\n      it('includes the invoice number', () => { ... })\n    })\n  })\n})\n```\n\n### 6. Setup and Teardown\n\n```typescript\ndescribe('DatabaseTests', () => {\n  beforeEach(() => {\n    vi.clearAllMocks()\n  })\n\n  afterEach(async () => {\n    await cleanup()\n  })\n\n  beforeAll(async () => {\n    await setupTestDatabase()\n  })\n\n  afterAll(async () => {\n    await teardownTestDatabase()\n  })\n})\n```\n\n### 7. Testing Error Cases\n\n```typescript\nit('handles API errors gracefully', async () => {\n  \u002F\u002F Mock API failure\n  vi.spyOn(global, 'fetch').mockRejectedValueOnce(new Error('Network error'))\n\n  const result = await fetchWithFallback()\n\n  expect(result.error).toBe('Network error')\n  expect(result.data).toBeNull()\n})\n\nit('throws on invalid input', () => {\n  expect(() => validateInput(null)).toThrow('Input required')\n})\n\nit('rejects promise on async error', async () => {\n  await expect(asyncFunction()).rejects.toThrow('Async error')\n})\n```\n\n## Running Tests\n\nResolve the repo's actual test commands per\n[references\u002Fverify-commands.md](references\u002Fverify-commands.md) rather than assuming\nscript names. Common Vitest invocations:\n\n```bash\n# Run all tests once (CI style; does not watch)\nnpx vitest run\n\n# Run a specific file\nnpx vitest run src\u002Flib\u002Fdiscount.test.ts\n\n# Run with coverage\nnpx vitest run --coverage\n\n# Watch mode (interactive only; never use as a gate)\nnpx vitest\n```\n\n## Review Checklist\n\nWhen reviewing tests:\n\n- [ ] Tests follow the project's configured file pattern\n- [ ] Async tests use `async\u002Fawait`\n- [ ] Descriptive test names (behavior-focused)\n- [ ] Assertions are specific (not just `.toBeTruthy()`)\n- [ ] Error cases are tested\n- [ ] Mocks are cleaned up in `beforeEach`\n- [ ] No hardcoded delays (use fake timers)\n- [ ] Integration tests use realistic ranges\n\n## Anti-Patterns\n\n```typescript\n\u002F\u002F Don't use vague assertions\nexpect(result).toBeTruthy()  \u002F\u002F Use specific: expect(result.id).toBe('123')\n\n\u002F\u002F Don't forget async\nit('test', () => {\n  fetchData()  \u002F\u002F Missing await!\n})\n\n\u002F\u002F Don't hardcode delays\nawait new Promise(r => setTimeout(r, 1000))  \u002F\u002F Use vi.useFakeTimers()\n\n\u002F\u002F Don't test implementation details\nexpect(component.state.count).toBe(1)  \u002F\u002F Test behavior, not state\n```\n","# Testing Skill\n\nApply this skill when writing, reviewing, or debugging tests.\n\n## Test Configuration\n\nRead the project's `vitest.config.*` (or the `test` block in `vite.config.*`) before writing\ntests, and match it. Typical settings to check:\n- **Environment:** `node` for server\u002Flibrary code, `jsdom` or `happy-dom` for DOM code\n- **Timeout:** raised (e.g. 30 seconds) for API\u002Fintegration tests\n- **Pattern:** where tests live, e.g. `src\u002F**\u002F*.test.ts` or colocated `*.test.ts`\n- **Env vars:** how test env vars are loaded (e.g. from an env file or a setup file)\n- **Path alias:** if the project uses path aliases (e.g. `@\u002F` mapping to `.\u002Fsrc\u002F`), use them in\n  imports and mocks exactly as the source code does\n\n## Core Patterns\n\n### 1. Test File Structure\n\n```typescript\nimport { describe, it, expect, beforeEach, vi } from 'vitest'\n\ndescribe('ModuleName', () => {\n  describe('functionName', () => {\n    it('returns expected result when given valid input', async () => {\n      \u002F\u002F Arrange\n      const input = { ... }\n\n      \u002F\u002F Act\n      const result = await functionName(input)\n\n      \u002F\u002F Assert\n      expect(result).toEqual(expected)\n    })\n\n    it('throws error when given invalid input', async () => {\n      await expect(functionName(null)).rejects.toThrow('Expected error')\n    })\n  })\n})\n```\n\n### 2. Async Tests\n\nAlways use `async\u002Fawait` for async operations:\n\n```typescript\n\u002F\u002F Correct\nit('fetches data from API', async () => {\n  const result = await fetchData()\n  expect(result).toBeDefined()\n})\n\n\u002F\u002F Wrong - missing await\nit('fetches data from API', () => {\n  const result = fetchData()  \u002F\u002F Promise, not result!\n  expect(result).toBeDefined()\n})\n```\n\n### 3. Specific and Realistic Assertions\n\nFor pure functions, assert exact values. For integration tests against live or variable data,\nuse range- and shape-based assertions:\n\n```typescript\n\u002F\u002F Pure function: exact values\nit('applies a percentage discount and rounds to cents', () => {\n  expect(applyDiscount(19.99, 0.15)).toBe(16.99)\n  expect(applyDiscount(100, 0)).toBe(100)\n})\n\n\u002F\u002F Integration: realistic ranges and shapes\nit('returns a plausible exchange rate', async () => {\n  const result = await getExchangeRate('USD', 'EUR')\n\n  \u002F\u002F Rate should be in a realistic range\n  expect(result.rate).toBeGreaterThan(0.5)\n  expect(result.rate).toBeLessThan(2)\n\n  \u002F\u002F Pair should match the request\n  expect(result.pair).toMatch(\u002FUSD\\\u002FEUR\u002F)\n\n  \u002F\u002F Required fields present\n  expect(result.source).toBeTruthy()\n  expect(result.fetchedAt).toBeInstanceOf(Date)\n})\n```\n\n### 4. Mocking an API Client Module\n\n```typescript\nimport { vi } from 'vitest'\n\n\u002F\u002F Mock the whole module (path must match the import used in the code under test)\nvi.mock('.\u002Flib\u002Fapi-client', () => ({\n  apiClient: {\n    get: vi.fn().mockResolvedValue({ data: mockData, error: null }),\n    post: vi.fn().mockResolvedValue({ data: { id: '123' }, error: null }),\n  },\n}))\n\n\u002F\u002F Or build a chainable query-builder mock for fluent SDKs\nconst mockDb = {\n  from: vi.fn().mockReturnValue({\n    select: vi.fn().mockReturnValue({\n      eq: vi.fn().mockResolvedValue({ data: [], error: null }),\n    }),\n  }),\n}\n```\n\n### 5. Test Organization\n\nGroup related tests with nested `describe`:\n\n```typescript\ndescribe('PaymentProvider', () => {\n  describe('Card payments', () => {\n    describe('charge', () => {\n      it('charges the exact amount in minor units', async () => { ... })\n      it('handles a declined card gracefully', async () => { ... })\n      it('retries once on a transient network error', async () => { ... })\n    })\n  })\n\n  describe('Bank transfers', () => {\n    describe('buildReference', () => {\n      it('includes the invoice number', () => { ... })\n    })\n  })\n})\n```\n\n### 6. Setup and Teardown\n\n```typescript\ndescribe('DatabaseTests', () => {\n  beforeEach(() => {\n    vi.clearAllMocks()\n  })\n\n  afterEach(async () => {\n    await cleanup()\n  })\n\n  beforeAll(async () => {\n    await setupTestDatabase()\n  })\n\n  afterAll(async () => {\n    await teardownTestDatabase()\n  })\n})\n```\n\n### 7. Testing Error Cases\n\n```typescript\nit('handles API errors gracefully', async () => {\n  \u002F\u002F Mock API failure\n  vi.spyOn(global, 'fetch').mockRejectedValueOnce(new Error('Network error'))\n\n  const result = await fetchWithFallback()\n\n  expect(result.error).toBe('Network error')\n  expect(result.data).toBeNull()\n})\n\nit('throws on invalid input', () => {\n  expect(() => validateInput(null)).toThrow('Input required')\n})\n\nit('rejects promise on async error', async () => {\n  await expect(asyncFunction()).rejects.toThrow('Async error')\n})\n```\n\n## Running Tests\n\nResolve the repo's actual test commands per\n[references\u002Fverify-commands.md](references\u002Fverify-commands.md) rather than assuming\nscript names. Common Vitest invocations:\n\n```bash\n# Run all tests once (CI style; does not watch)\nnpx vitest run\n\n# Run a specific file\nnpx vitest run src\u002Flib\u002Fdiscount.test.ts\n\n# Run with coverage\nnpx vitest run --coverage\n\n# Watch mode (interactive only; never use as a gate)\nnpx vitest\n```\n\n## Review Checklist\n\nWhen reviewing tests:\n\n- [ ] Tests follow the project's configured file pattern\n- [ ] Async tests use `async\u002Fawait`\n- [ ] Descriptive test names (behavior-focused)\n- [ ] Assertions are specific (not just `.toBeTruthy()`)\n- [ ] Error cases are tested\n- [ ] Mocks are cleaned up in `beforeEach`\n- [ ] No hardcoded delays (use fake timers)\n- [ ] Integration tests use realistic ranges\n\n## Anti-Patterns\n\n```typescript\n\u002F\u002F Don't use vague assertions\nexpect(result).toBeTruthy()  \u002F\u002F Use specific: expect(result.id).toBe('123')\n\n\u002F\u002F Don't forget async\nit('test', () => {\n  fetchData()  \u002F\u002F Missing await!\n})\n\n\u002F\u002F Don't hardcode delays\nawait new Promise(r => setTimeout(r, 1000))  \u002F\u002F Use vi.useFakeTimers()\n\n\u002F\u002F Don't test implementation details\nexpect(component.state.count).toBe(1)  \u002F\u002F Test behavior, not state\n```\n",{"name":5,"license":15,"metadata":24,"description":7},{"owner":9,"version":25},"0.1.0","main","0e72138c24cb36f409dcf3abe74fd283ebdfe998","skills\u002Ftesting","https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills","https:\u002F\u002Fgithub.com\u002Frazorvision","http:\u002F\u002Fwww.razorvision.net","Software services firm with a focus in the finance industry.","2026-11-08 06:34:17",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add razorvision\u002Fclara-skills --skill testing",{"tool":40,"command":41},"bunx","bunx skills add razorvision\u002Fclara-skills --skill testing",{"tool":43,"command":44},"pnpm","pnpm dlx skills add razorvision\u002Fclara-skills --skill testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills\u002Fblob\u002Fmain\u002Fskills\u002Ftesting\u002FSKILL.md",true,[48],{"path":49,"resourceType":50,"resourceTypeDesc":51,"sizeBytes":52,"sourceHtmlUrl":53},"references\u002Fverify-commands.md","REFERENCE","参考文档",3526,"https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills\u002Fblob\u002Fmain\u002Fskills\u002Ftesting\u002Freferences\u002Fverify-commands.md",[55,62,68,75,82,89],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":19},"01M7EKD05TFNCAT51YJ7VV486B","\u003Cfolder-name-lowercase-hyphens>","\u003CWhat it does. Use when the user asks for \u003CX> or mentions \u003CY>.>","https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills\u002Fblob\u002Fmain\u002Ftemplates\u002Fminimal-skill\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"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":65,"categories":66,"keywords":67,"publishedAt":19},"01M7EKCZ8AM1YBKFSH7JNK097P","full-skill","https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills\u002Fblob\u002Fmain\u002Ftemplates\u002Ffull-skill\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M7EKCVJ2RBJ72MSFZ87DV801","typescript","Guides TypeScript best practices for strict-mode projects, covering discriminated unions, interface contracts, nullability, type guards, utility types, async return types, const assertions, and a review checklist of common anti-patterns. Use when writing, reviewing, or debugging TypeScript code or type definitions.","https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills\u002Fblob\u002Fmain\u002Fskills\u002Ftypescript\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7EKCHY6AN7HRM7DV6DD7MST","staleness-check","Sweeps the repo and related sources for artifacts that a just-completed body of work should have updated but did not, such as stale doc indexes, READMEs, ADRs, registries, agent instruction files, agent memory files, issue status, and cross-references, then reports each stale item with a proposed fix. Use at the end of an epic, feature, or executed plan, or when the user says \"staleness check\", \"did we miss anything\", \"are we done\", or \"anything stale\".","https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills\u002Fblob\u002Fmain\u002Fskills\u002Fstaleness-check\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M7EKCDGZQCRDC6DRXYEJMR66","software-architecture","Guides architectural decisions using Clean Architecture, separation of concerns, and SOLID principles, covering where new code should live, how modules depend on each other, and which anti-patterns to avoid, with a review checklist. Use when designing a new module or feature structure, refactoring code organization, deciding where code belongs, or reviewing a codebase's architecture.","https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsoftware-architecture\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":19},"01M7EKCA3JSAKDVP8TA2BN60DC","root-cause","Traces a bug backward through the call chain to the original trigger instead of patching where the error surfaces, then fixes it at the source and adds defensive validation at intermediate layers. Use when debugging an error, a failing test, or unexpected behavior where the symptom appears far from its cause.","https:\u002F\u002Fgithub.com\u002Frazorvision\u002Fclara-skills\u002Fblob\u002Fmain\u002Fskills\u002Froot-cause\u002FSKILL.md",[],[]]