Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问clear审计通过

test-frontend-units测试前端单元

Agent Skill

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

总安装

570

周安装

24

GitHub Stars

86

下载量

43
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/marcelmichau/fake-survey-generator --skill test-frontend-units

简介

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。

  • 适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。
  • 使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段。
  • 涉及页面改动时,应配合本地预览和构建检查确认视觉效果。
  • 安装方式:github,需通过 npx skills add 命令从指定仓库添加。

SKILL.md

Test Frontend Units Skill

Use this skill to run unit tests for React components to validate that features are properly tested and components function as expected.

What This Skill Does

  1. Runs npm test -- --run from the src/client/ui directory
  2. Executes Vitest test suite including:

- src/components/CreateSurvey.test.tsx (15 tests - survey creation form) - src/components/GetSurvey.test.tsx (17 tests - survey fetching and display) - src/components/MySurveys.test.tsx (18 tests - user surveys listing)

  1. Tests run in jsdom environment simulating browser APIs
  2. Includes Auth0 authentication mocking and testing utilities
  3. Collects test results including:

- Total tests run, passed, failed, skipped - Failed test names and error details - Test execution time per file

  1. Reports failures with specific test names and assertion errors
  2. Exits with failure status if any tests fail

Test Framework & Environment

  • Framework: Vitest v4.0.17
  • Environment: jsdom (browser API simulation)
  • Testing Library: @testing-library/react with @testing-library/user-event
  • Auth Mocking: Auth0 useAuth0 hook mocked in test setup
  • Utilities: Custom test utilities with render wrapper for consistent test setup

When to Use

  • After implementing new React component features to ensure they're covered by tests
  • Before deploying frontend changes to validate no regressions
  • To check component functionality and user interactions
  • After modifying existing components to ensure tests still pass
  • To verify form handling, API integration, and state management
  • During feature development to validate component behavior

How the Agent Should Use This Skill

  1. Prepare: Navigate to repository root
  2. Invoke: Run tests from repository root: ``

cd src/client/ui && npm test -- --run

- The `--run` flag executes tests once and exits (non-watch mode)
- Tests execute with jsdom environment for browser API simulation
3. **Parse Output**: Monitor stdout and stderr for:
- Test file summary (e.g., "Test Files  3 passed (3)")
- Test count summary (e.g., "Tests  50 passed (50)")
- Individual test execution times
- Failed test names and assertion errors
- Error details and stack traces if failures occur
4. **Handle Failures**: If any tests fail:
- Extract failed test names and file locations
- Review assertion errors or exception messages
- Report specific failures to user with context
- Halt further validation (don't proceed to Aspire/E2E)
5. **Report Success**: Include test count and execution time in report

## Success Criteria

- Exit code: 0
- All tests pass (output shows `failed: 0` or similar)
- No error output to stderr indicating test execution issues
- Output shows "Test Files X passed (X)" with all files passing
- Vitest runs and completes successfully
- Tests complete in reasonable time (under 5 seconds)

## Failure Indicators

- Exit code: 1 or non-zero
- Stdout contains failed test counts (e.g., `failed: 2`)
- Individual test failure messages with names and assertion details
- Console errors from test setup or mocking issues
- Timeout errors in async tests
- Import or type errors in test files

## Test Files & Components

### CreateSurvey.test.tsx
- **Component**: CreateSurvey (survey creation form)
- **Tests**: 15 test cases
- **Coverage**:
- Form rendering and input fields
- Adding/removing survey options
- Form validation and submission
- Error handling and success messages
- State management and form reset
- **Key Tests**:
- Renders form with correct fields
- Updates input values on user type
- Adds/removes options from survey
- Submits form with correct API payload
- Shows error/success messages

### GetSurvey.test.tsx
- **Component**: GetSurvey (survey fetching and display)
- **Tests**: 17 test cases
- **Coverage**:
- Survey fetching by ID
- Form submission for manual fetch
- Survey result display
- Error state handling (404, network errors)
- Loading indicators
- Component updates on prop changes
- **Key Tests**:
- Auto-fetches survey when ID prop changes
- Displays survey data and result breakdown
- Shows error messages for failed requests
- Handles 404 and network errors gracefully
- Updates input values on user interaction

### MySurveys.test.tsx
- **Component**: MySurveys (user surveys listing)
- **Tests**: 18 test cases
- **Coverage**:
- Fetching user's surveys
- Displaying surveys in table format
- Loading skeletons during fetch
- Empty state when no surveys exist
- Error handling and error messages
- User interactions (clicking buttons, rapid clicks)
- Multiple successive fetches
- **Key Tests**:
- Renders survey list with correct data
- Shows loading skeleton while fetching
- Shows empty state when no surveys
- Handles API errors gracefully
- Fetches surveys when button clicked

## Common Test Patterns Used

// Component rendering test render(<ComponentName />); expect(screen.getByRole("heading", { name: /title/i })).toBeInTheDocument();

// Form interaction test with userEvent const input = screen.getByPlaceholderText("placeholder"); await user.type(input, "value"); expect(input).toHaveValue("value");

// Async API test with mock const mockApiCall = vi.fn().mockResolvedValue({ok: true, json: async () => data}); vi.mocked(hooks.useApiCall).mockReturnValue({apiCall: mockApiCall}); await user.click(button); await waitFor(() => expect(mockApiCall).toHaveBeenCalled());

// Error handling test mockApiCall.mockRejectedValue(new Error("Network error")); // ... trigger component action await waitFor(() => expect(screen.getByText("Network error")).toBeInTheDocument());


## Test Setup & Infrastructure

- **vitest.config.ts**: Configures jsdom environment, global APIs, setup files
- **src/test/setup.ts**: Auth0 useAuth0 hook mock, window.matchMedia mock
- **src/test/test-utils.tsx**: Custom render function with testing utilities wrapper
- **Mock Data**: Realistic survey and user data structures matching API types

## Notes

- Tests are located in `src/client/ui/src/components/` directory
- All tests use jsdom for browser API simulation (window, document, etc.)
- Auth0 authentication is mocked so tests don't require real tokens
- Tests use userEvent for realistic user interaction simulation
- Custom hooks (useApiCall, useSurveyFetch) are mocked via vi.mocked()
- Tests include loading states, error states, and empty states
- Current test suite: **50 tests passing** (100% success rate)
- Run with `npm test -- --ui` for interactive Vitest UI dashboard
- Run with `npm test -- --coverage` to generate coverage report
- Test execution time: ~1.5-2 seconds for full suite

## Common Issues & Troubleshooting

| Issue | Cause | Solution |
| --- | --- | --- |
| "Unable to find an element" error | Selector doesn't match any elements | Use more specific selectors (getByRole, getByLabelText) or use screen.debug() |
| Timeout in waitFor | Async operation not completing | Check mock setup, increase timeout, verify component updates state |
| Import errors in tests | Wrong import paths | Use relative paths from test file location (e.g., `../test/test-utils`) |
| Type errors with mocks | Mock return type mismatch | Ensure mock data matches component prop types |
| Auth0 not mocked | Setup.ts not loading | Verify vitest.config.ts has correct setupFiles path |

## Next Steps After Success

Once all frontend unit tests pass, typically invoke:

- **Validate Aspire Runtime Skill** - to start the full application environment
- **Validate E2E Skill** - to run end-to-end acceptance tests and verify features work in running application

## Dependencies

Run these from `src/client/ui` directory once:

npm install


Installed packages:

- `vitest` - test runner
- `@testing-library/react` - component testing utilities
- `@testing-library/user-event` - realistic user interaction simulation
- `@testing-library/jest-dom` - custom matchers
- `@vitest/ui` - interactive test dashboard
- `jsdom` - browser environment simulation

## References

- Test files: `src/client/ui/src/components/*.test.tsx`
- Vitest docs: [https://vitest.dev/](https://vitest.dev/)
- Testing Library docs: [https://testing-library.com/docs/react-testing-library/intro](https://testing-library.com/docs/react-testing-library/intro)
- Test utilities: `src/client/ui/src/test/`

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

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

平台分布

Claude Code

28.51%
按下载量换算12

Antigravity

25.1%
按下载量换算11

windsurf

19%
按下载量换算8

Codex

11.71%
按下载量换算5

trae

8.15%
按下载量换算4

OpenCode

3.24%
按下载量换算1

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills