ワンクリックで
frontend-testing
Vitest/Vue 3 testing patterns for trader-pro frontend. Load when writing or debugging frontend tests
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Vitest/Vue 3 testing patterns for trader-pro frontend. Load when writing or debugging frontend tests
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
External API evaluation and MCP server wrapper generation. Load when integrating a REST/GraphQL API as a workspace tool
Capability-based provider system patterns. Load when creating providers or wiring module-provider integration
Full-stack WebSocket subscription development. Load when adding WS routes, topic services, or debugging WS data flows
Systematic Python type error resolution (mypy/pyright). Load when fixing backend type check failures
Type-first Python with Pydantic, Protocol, and discriminated unions. Load when writing models or enforcing typing
Systematic type error resolution for Python (mypy/pyright) and TypeScript (vue-tsc). Use when fixing type errors, resolving type check failures, or optimizing type imports.
| name | frontend-testing |
| description | Vitest/Vue 3 testing patterns for trader-pro frontend. Load when writing or debugging frontend tests |
| user-invocable | false |
Vitest and Vue 3-specific testing methodology for the trader-pro frontend. Covers component testing, service auto-detection, WebSocket mocking, and project conventions. Apply test-strategy skill first for general methodology, then this skill for Vitest/Vue patterns.
frontend/src/
├── components/__tests__/ # Component tests
│ └── {Component}.spec.ts
├── services/__tests__/ # Service tests (highest value)
│ └── {service}.spec.ts
├── plugins/__tests__/ # Plugin/WebSocket tests
│ └── {plugin}.spec.ts
└── stores/__tests__/ # Pinia store tests
└── {store}.spec.ts
Priority: Service & plugin tests > component tests (higher signal-to-noise).
| Target | Pattern | Setup |
|---|---|---|
| Service class | Auto-detection new Service(true) | No vi.mock() needed |
| Vue component | mount(Component) | @vue/test-utils |
| WebSocket | vi.stubGlobal('WebSocket', Mock) | Custom MockWebSocket class |
| Pinia store | setActivePinia(createPinia()) | In beforeEach |
| Plugin/composable | Direct import + isolated call | No special setup |
const service = new ApiService(true) // Auto-detects test env via process.env.VITEST
const result = await service.getHealthStatus()
expect(result.status).toBe('ok')
Avoid vi.mock() when the service supports mock mode via constructor.
import { mount } from '@vue/test-utils'
import MyComponent from '../MyComponent.vue'
const wrapper = mount(MyComponent)
expect(wrapper.find('header').exists()).toBe(true)
await wrapper.vm.$nextTick()
class MockWebSocket {
static CONNECTING = 0; static OPEN = 1; static CLOSING = 2; static CLOSED = 3
readyState = MockWebSocket.CONNECTING
simulateOpen() {
this.readyState = MockWebSocket.OPEN
this.onopen?.(new Event('open'))
}
simulateMessage(data: object) {
this.onmessage?.({ data: JSON.stringify(data) } as MessageEvent)
}
}
beforeEach(() => {
vi.stubGlobal('WebSocket', vi.fn(() => new MockWebSocket()))
})
import { setActivePinia, createPinia } from 'pinia'
beforeEach(() => { setActivePinia(createPinia()) })
{Name}.spec.ts (NOT .test.ts)describe('{ComponentOrService}') → beforeEach() → it('behavior')it('shows loading state when data is pending')it() blockclients_generated/ are excluded — don't mock them, they're tested via backend contractsFrontend tests auto-generate clients from backend specs before running. The make -C frontend test target handles this automatically. Never run raw npm run test:unit.
make -C frontend test # Run tests once (--bail=1, auto-generates clients)
make -C frontend test-backend # Run tests with real backend (not mock)
make -C frontend lint # Lint (auto-generates clients first)
make -C frontend type-check # TypeScript check (auto-generates clients first)
| Purpose | Location |
|---|---|
| Test setup & client validation | frontend/src/test-setup.ts |
| Vitest config | frontend/vitest.config.ts |
| Service test README | frontend/src/services/__tests__/README.md |
vi.mock() when service supports auto-detection — prefer constructor pattern.test.ts extension — project standard is .spec.tsnpm run test:unit directly — use make -C frontend test*.spec.ts files first to match existing patterns