frontend-testing-guideline
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:
- auth flow and route guards
- store behavior
- response envelope unwrapping
- pagination behavior
- form validation and submission flow
- critical rendering logic
- 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/meconsumption 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.tsLoginPage.test.tsuseAuth.test.tsauth.guard.test.ts
Avoid vague names like:
test.tscomponent.spec.tsfor 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
