AgentSkillsCN

testing:unit-tests

为组件、模块、Store及实用工具编写全面的单元测试。 在被要求编写测试、增加测试覆盖率,或针对特定文件进行测试时使用。

SKILL.md
--- frontmatter
name: testing:unit-tests
description: |
  Create comprehensive unit tests for components, modules, stores, and utilities.
  Use when asked to write tests, add test coverage, or test a specific file.

Unit Test Creation

Create unit tests following project conventions.

Usage

  • /testing:unit-tests [target] - Create tests for specific file
  • /testing:unit-tests scan - Find files needing tests

Test Patterns

<!-- Customize these patterns for your framework -->

Component Testing

typescript
import { describe, expect, it } from 'vitest';

describe('MyComponent', () => {
  it('renders correctly', async () => {
    // Mount component with test utilities
    // Assert expected behavior
  });
});

Module/Composable Testing

typescript
import { describe, expect, it } from 'vitest';

describe('useMyModule', () => {
  it('returns expected structure', () => {
    const result = useMyModule();
    expect(result).toBeDefined();
  });
});

Store Testing

typescript
import { describe, expect, it } from 'vitest';

describe('MyStore', () => {
  it('initializes correctly', () => {
    const store = useMyStore();
    expect(store.items).toEqual([]);
  });
});

File Locations

SourceTest Location
src/components/Card.vuetests/components/Card.test.ts
src/composables/useData.tstests/composables/useData.test.ts
src/stores/data.tstests/stores/data.test.ts

Workflow

  1. Analyze target file structure and exports
  2. Create test file in appropriate directory
  3. Cover: happy path, edge cases, error conditions
  4. Run tests to verify
  5. Check coverage improvement