← 返回列表
全部 Skill›开发 Development›frontend-testing-guideline

frontend-testing-guideline

作者 @findsun-vn · 语言 en
Guide Vue 3 frontend test generation for module-based architecture, Pinia/Vue Router flows, OpenAPI-safe integration assumptions, and Ant Design Vue UI behavior.
开发 Development前端开发通用待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
0
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

Skill: frontend-testing-guideline

Purpose

Ensure generated frontend tests are:

  • module-based
  • type-aware
  • aligned with the single Vue app architecture
  • consistent with OpenAPI response handling
  • practical for pages, stores, composables, and route guards

Scope

Use this skill when generating or reviewing tests for:

  • module pages
  • module components
  • module stores
  • module composables
  • route guards
  • auth flows
  • response wrapper handling
  • pagination behavior

Frontend Test Location Rule

Module-scoped frontend tests should live under:

frontend/src/modules/<module_name>/__tests__/

Optional app-level or integration-style frontend tests may live under:

  • frontend/tests/
  • frontend/tests/e2e/
  • frontend/tests/setup/
  • frontend/tests/utils/

Keep business-specific tests close to the module when practical.


Frontend Testing Stack Assumption

Preferred tools:

  • Vitest
  • Vue Test Utils
  • Pinia testing helpers
  • Vue Router test support where needed

Use browser-style E2E only for critical journeys, not everything by default.


Coverage Priorities

Prioritize tests for:

  1. auth flow and route guards
  2. store behavior
  3. response envelope unwrapping
  4. pagination behavior
  5. form validation and submission flow
  6. critical rendering logic
  7. error/loading/empty states

Do not focus mainly on low-value snapshot noise.


API Contract Awareness Rule

Frontend tests must reflect that successful API responses use:

type ApiResponse<T> = {

code: number

message: string

data: T

}

Tests must verify that stores/composables/pages correctly read business payload from:

  • response.data

not from a fake raw top-level payload.


Pagination Rule

Frontend tests for paginated flows must reflect:

type PageResponse<T> = {

content: T[]

page: number

size: number

total: number

}

wrapped inside:

ApiResponse<PageResponse<T>>

Tests should verify:

  • pagination state mapping
  • table/list data mapping
  • page/size/total usage
  • loading/error transitions where relevant

Store Test Rule

Module store tests should verify:

  • loading state changes
  • error state handling
  • API call orchestration
  • correct response unwrapping
  • correct success/failure state updates
  • auth/token/current-user state when applicable
  • pagination state handling when applicable

Stores must be tested as store logic, not by bypassing them completely.


Composable Test Rule

Composable tests should verify:

  • reusable UI logic
  • form helpers
  • search/filter state
  • modal/drawer state
  • auth-related local flow helpers
  • route-aware behavior where relevant

Avoid duplicating full page rendering tests if the composable already isolates the logic well.


Component / Page Test Rule

Component and page tests should verify important UI behavior such as:

  • correct rendering of key fields
  • correct interaction flow
  • form validation messaging
  • loading state rendering
  • empty state rendering
  • error state rendering
  • submission behavior
  • route redirects or guard outcomes where relevant

Do not over-test every Ant Design Vue internal detail.

Focus on your app logic and visible business behavior.


Auth Frontend Test Rule

When the module is auth or includes auth-related flows, frontend tests should cover as appropriate:

  • login form submission
  • register form submission
  • auth store login/logout/current-user behavior
  • protected-route redirect behavior
  • bearer-token-aware auth integration assumptions
  • unauthorized state cleanup
  • current-user bootstrap behavior
  • /api/auth/me consumption as current-user source

Tests must not assume cookie-session-first auth when the approved strategy is stateless JWT.


Route Guard Test Rule

When route guards exist, tests should verify:

  • unauthenticated user redirected from protected routes
  • authenticated user allowed into protected routes
  • role/permission restriction behavior when route meta requires it
  • centralized auth store integration
  • no dependence on arbitrary local UI flags as the trusted auth source

Form Validation Rule

Frontend tests should verify important validation behavior consistent with:

  • OpenAPI required fields
  • backend validation expectations
  • auth/business flow rules where relevant

This is especially important for:

  • login
  • register
  • create/edit forms
  • search/filter forms with strict behavior

Error / Loading / Empty State Rule

Tests should cover the visible user-facing behavior for:

  • loading state
  • API error state
  • permission error state
  • empty list / no data state
  • success feedback where important

Do not test only success paths.


Sensitive Auth Value Rule

Frontend tests and fixtures must avoid careless exposure of:

  • real passwords
  • token values
  • raw credential logs
  • internal security-only fields

Use fake data safely.

Do not normalize insecure debug patterns.


Naming Rule

Test file names should remain clear and module-aligned.

Examples:

  • auth.store.test.ts
  • LoginPage.test.ts
  • useAuth.test.ts
  • auth.guard.test.ts

Avoid vague names like:

  • test.ts
  • component.spec.ts for unrelated mixed behavior

Forbidden Patterns

  • assuming API payload is top-level raw data
  • bypassing store tests when store logic is critical
  • overfitting tests to Ant Design Vue internal markup
  • ignoring route guard behavior for protected pages
  • ignoring loading/error/empty states
  • designing auth tests around cookie sessions when the approved backend strategy is stateless JWT

Final Goal

Frontend tests should be:

  • module-focused
  • OpenAPI-aware
  • store-friendly
  • route-aware
  • auth-safe
  • useful for regression protection
评论
Ffindsun-vn
findsun-vn
findsun-vn/E-Commerce
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@findsun-vn
所属大类开发 Development / 前端开发
国内可用性通用
最近源活动—
风险提示无
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。