Token导航 LogoToken导航TokenDH.com
待分类权限需确认github未标认证来源可访问许可证需确认审计未展示

vue-vite-testingVue Vite 测试

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

294

周安装

12

GitHub Stars

2

下载量

94
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:vue-vite-testing(Vue Vite 测试)
来源仓库:https://github.com/eva813/vue3-skills
仓库路径:skills/vue-vite-testing
安装命令:
npx skills add https://github.com/eva813/vue3-skills --skill vue-vite-testing
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/eva813/vue3-skills --skill vue-vite-testing

简介

用于 Vue Vite 测试相关的技术支持。

  • 适合处理 Vue 3 + Vite 环境下的测试配置。
  • 可协助生成测试用例和测试工具链配置。vue-vite-testing 属于待分类类 Skill,可作为该场景下的辅助能力补充。
  • 使用时应确保与 Vite 构建工具和测试框架兼容。
  • 安装方式:通过 GitHub 仓库安装,适用于 Claude 等宿主。

SKILL.md

name
vue-vite-testing
description
Comprehensive unit testing guide for Vue 3 + Vite projects using Vitest and Vue Test Utils. Use when writing or reviewing unit tests for Vue components, composables, Pinia stores, or TypeScript/JavaScript utilities in Vite-based projects. Covers test structure, best practices, mocking strategies, and Vue-specific testing patterns.

Vue + Vite Unit Testing

Overview

Generate comprehensive, production-ready unit tests for Vue 3 + Vite projects using Vitest framework. Follow industry best practices for testing Vue components, composables, Pinia stores, and TypeScript utilities with proper isolation, mocking, and edge case coverage.

Testing Framework Setup

Primary Stack:

  • Vitest: Fast unit test framework built for Vite
  • Vue Test Utils: Official testing utility library for Vue components
  • @vitest/ui: Optional UI for test visualization

Import pattern:

import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { mount, shallowMount } from '@vue/test-utils';

Testing Workflow

Follow this systematic approach for all testing tasks:

1. Code Analysis Phase

Before writing any tests:

  • Analyze the code structure and identify all public interfaces
  • Identify external dependencies (APIs, stores, composables, modules)
  • Note all possible code paths, conditions, and edge cases
  • Ask clarifying questions about:

- Missing type definitions or constants - Unclear business logic or validation rules - External API contracts or data structures - Expected error handling behaviors

Only proceed to writing tests after full code understanding.

2. Test Design Phase

Plan test coverage:

  • Happy path scenarios (expected inputs and outputs)
  • Error handling and failure modes
  • Edge cases (empty arrays, null values, boundary conditions)
  • Async operations (loading, success, error states)
  • User interactions (clicks, inputs, form submissions)
  • Lifecycle hooks and reactivity

For Vue components, identify:

  • Props validation and default values
  • Emitted events and their payloads
  • Slots usage and content projection
  • Computed properties and watchers
  • Component lifecycle behavior

For composables, identify:

  • Input parameters and return values
  • State management and reactivity
  • Side effects (API calls, localStorage, timers)
  • Cleanup requirements

Test Structure Standards

Standard Test Template

import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';

describe('ModuleName or ComponentName', () => {
  // Top-level test variables
  let mockDependency: MockType;
  
  beforeEach(() => {
    // Reset state before each test
    mockDependency = createMockDependency();
  });

  afterEach(() => {
    // Cleanup after each test
    vi.clearAllMocks();
  });

  describe('method or feature name', () => {
    it('should handle happy path scenario', () => {
      // Arrange: Set up test data and mocks
      const input = { /* test data */ };
      
      // Act: Execute the code under test
      const result = functionUnderTest(input);
      
      // Assert: Verify expected outcomes
      expect(result).toBe(expectedValue);
    });

    it('should handle error case', async () => {
      // Arrange
      mockDependency.method.mockRejectedValue(new Error('test error'));
      
      // Act & Assert
      await expect(functionUnderTest()).rejects.toThrow('test error');
    });

    it('should handle edge case: empty input', () => {
      // Test edge cases
      expect(functionUnderTest([])).toEqual([]);
    });
  });
});

AAA Pattern (Arrange-Act-Assert)

Always structure individual tests using AAA:

it('should calculate total price correctly', () => {
  // Arrange: Set up test data
  const items = [
    { price: 100, quantity: 2 },
    { price: 50, quantity: 1 }
  ];
  
  // Act: Execute the function
  const total = calculateTotal(items);
  
  // Assert: Verify the result
  expect(total).toBe(250);
});

Vue-Specific Testing Patterns

1. Component Testing

Decide between mount vs shallowMount:

  • Use mount() for integration testing with child components
  • Use shallowMount() for isolated unit testing (stubs child components)
import { mount } from '@vue/test-utils';
import MyComponent from './MyComponent.vue';

describe('MyComponent', () => {
  it('should render with props', () => {
    const wrapper = mount(MyComponent, {
      props: {
        title: 'Test Title',
        count: 5
      }
    });
    
    expect(wrapper.find('h1').text()).toBe('Test Title');
    expect(wrapper.find('.count').text()).toBe('5');
  });

  it('should emit event on button click', async () => {
    const wrapper = mount(MyComponent);
    
    await wrapper.find('button').trigger('click');
    
    expect(wrapper.emitted('submit')).toBeTruthy();
    expect(wrapper.emitted('submit')[0]).toEqual([{ data: 'value' }]);
  });

  it('should handle v-model binding', async () => {
    const wrapper = mount(MyComponent, {
      props: {
        modelValue: 'initial'
      }
    });
    
    await wrapper.find('input').setValue('updated');
    
    expect(wrapper.emitted('update:modelValue')[0]).toEqual(['updated']);
  });
});

See references/component-testing.md for complete component testing patterns including slots, provide/inject, and async components.

2. Composables Testing

import { composableUnderTest } from './useFeature';

describe('useFeature composable', () => {
  it('should initialize with default state', () => {
    const { state, count } = composableUnderTest();
    
    expect(state.value).toBe('idle');
    expect(count.value).toBe(0);
  });

  it('should update reactive state', () => {
    const { increment, count } = composableUnderTest();
    
    increment();
    
    expect(count.value).toBe(1);
  });

  it('should handle async operations', async () => {
    const { fetchData, data, loading } = composableUnderTest();
    
    expect(loading.value).toBe(false);
    
    const promise = fetchData();
    expect(loading.value).toBe(true);
    
    await promise;
    expect(loading.value).toBe(false);
    expect(data.value).toBeDefined();
  });
});

See references/composables-testing.md for advanced composable testing patterns including side effects and cleanup.

3. Pinia Store Testing

import { setActivePinia, createPinia } from 'pinia';
import { useMyStore } from './myStore';

describe('myStore', () => {
  beforeEach(() => {
    setActivePinia(createPinia());
  });

  it('should initialize with default state', () => {
    const store = useMyStore();
    
    expect(store.items).toEqual([]);
    expect(store.loading).toBe(false);
  });

  it('should add item to store', () => {
    const store = useMyStore();
    const newItem = { id: 1, name: 'Test' };
    
    store.addItem(newItem);
    
    expect(store.items).toContainEqual(newItem);
  });

  it('should handle async actions', async () => {
    const store = useMyStore();
    
    await store.fetchItems();
    
    expect(store.loading).toBe(false);
    expect(store.items.length).toBeGreaterThan(0);
  });
});

See references/store-testing.md for Pinia store testing patterns including getters, mutations, and actions.

Mocking Strategies

External Dependencies

// Mock API calls
vi.mock('@/api/users', () => ({
  fetchUsers: vi.fn(),
  createUser: vi.fn()
}));

// Mock composables
vi.mock('@/composables/useAuth', () => ({
  useAuth: vi.fn(() => ({
    user: { id: 1, name: 'Test User' },
    isAuthenticated: true,
    login: vi.fn(),
    logout: vi.fn()
  }))
}));

// Mock Vue Router
const mockRouter = {
  push: vi.fn(),
  replace: vi.fn()
};

const wrapper = mount(Component, {
  global: {
    mocks: {
      $router: mockRouter
    }
  }
});

Timers and Delays

import { vi } from 'vitest';

describe('setTimeout behavior', () => {
  beforeEach(() => {
    vi.useFakeTimers();
  });

  afterEach(() => {
    vi.useRealTimers();
  });

  it('should execute callback after delay', () => {
    const callback = vi.fn();
    
    setTimeout(callback, 1000);
    
    expect(callback).not.toHaveBeenCalled();
    
    vi.advanceTimersByTime(1000);
    
    expect(callback).toHaveBeenCalledOnce();
  });
});

Testing Best Practices

1. Test Isolation

  • Each test should be independent and not rely on other tests
  • Use beforeEach to reset state
  • Clean up mocks with vi.clearAllMocks() or vi.resetAllMocks()

2. Descriptive Test Names

// ✅ Good: Clear and descriptive
it('should display error message when API request fails', () => {});

// ❌ Bad: Vague and unclear
it('should work', () => {});

3. Avoid Test Logic

// ❌ Bad: Contains loops and conditions
it('should validate all items', () => {
  for (const item of items) {
    if (item.type === 'special') {
      expect(validate(item)).toBe(true);
    }
  }
});

// ✅ Good: Simple and direct
it('should validate special item', () => {
  const specialItem = { type: 'special', value: 100 };
  expect(validate(specialItem)).toBe(true);
});

it('should validate normal item', () => {
  const normalItem = { type: 'normal', value: 50 };
  expect(validate(normalItem)).toBe(true);
});

4. Test Coverage Priority

  1. Critical business logic (payment, authentication, data validation)
  2. Complex algorithms (calculations, transformations)
  3. Error handling (edge cases, failure modes)
  4. User interactions (forms, buttons, navigation)
  5. Integration points (API calls, external services)

5. Async Testing

// ✅ Properly handle async operations
it('should fetch data successfully', async () => {
  const result = await fetchData();
  expect(result).toBeDefined();
});

// ✅ Use resolves/rejects for promises
await expect(fetchData()).resolves.toEqual(expectedData);
await expect(failingOperation()).rejects.toThrow('Error message');

Complete Test Deliverables

When generating tests, always provide:

  1. Complete test suites - No placeholders or "// TODO" comments
  2. All edge cases covered - Empty inputs, null values, boundaries
  3. Proper imports - All necessary test utilities and dependencies
  4. Appropriate mocks - For external dependencies and side effects
  5. Clear test descriptions - Self-documenting test names
  6. Proper cleanup - afterEach hooks where needed

Reference Files

For detailed examples and advanced patterns:

  • references/component-testing.md - Comprehensive component testing patterns (slots, teleport, provide/inject, async components)
  • references/composables-testing.md - Advanced composable testing (side effects, watchers, cleanup)
  • references/store-testing.md - Pinia store testing patterns (getters, actions, state management)

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.43%
按下载量换算33

Claude

29.49%
按下载量换算28

Cursor

17.28%
按下载量换算16

Gemini CLI

8%
按下载量换算8

安全审计

暂无安全审计结果可展示。

权限和风险

权限需确认

当前来源未能明确判断权限范围,默认进入异常复核队列。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills