用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Dev-Toolbelt/dev-team-agents --skill decoupled-frontend命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | decoupled-frontend |
| description | Testing an SPA against a separate API — MSW handlers, async state coverage, factories. |
Applies when the frontend is a separate deployable consuming a REST or GraphQL API it does not own. The API is a contract to be mocked faithfully, not an implementation detail to be stubbed away.
| Signal | Meaning |
|---|---|
API base URL in env (VITE_API_URL, NEXT_PUBLIC_API_URL, REACT_APP_API_URL) | Frontend talks to an external API |
msw in devDependencies, or a mocks//handlers/ directory | MSW already adopted — extend it, do not add a second mocking layer |
| Generated API client / OpenAPI or GraphQL schema in the repo | Typed contract available — bind mocks to it |
| Backend and frontend in the same deployable (SSR templates, server actions only) | This skill does not apply |
Prefer Mock Service Worker (MSW) over mocking fetch/axios or the data-fetching library. MSW intercepts at the network level, so the component, the client, and the serialization all run as they do in production.
Handler rules
handlers/auth.ts, handlers/orders.ts) so a test can override one domain without redefining the rest.server.use(...).// Override for a specific test
server.use(
http.get('/api/orders', () => HttpResponse.json({ error: 'Unauthorized' }, { status: 401 }))
);
server.resetHandlers() in afterEach) so an error case cannot leak into the next test.| State | Must be tested |
|---|---|
| Loading | Skeleton / spinner visible while the request is in flight |
| Success | Data renders correctly |
| Empty | Empty-state UI shown when the response is [] or null |
| Error | Error message shown on 4xx / 5xx / network failure |
| Optimistic update | UI reflects the change immediately, and rolls back when the server rejects it |
A feature with only a success test is not covered — the states users actually complain about are the other four.
skills/testing/contract-testing/SKILL.md (consumer-driven contracts or schema validation in CI).fishery-style builders) rather than inline literals scattered across files.buildOrder({ status: 'cancelled' }).| Priority | Selector | Use for |
|---|---|---|
| 1 | getByRole | Accessible role — button, textbox, heading |
| 2 | getByLabelText | Form controls with an associated label |
| 3 | getByText | Visible, stable text content |
| 4 | getByTestId | data-testid fallback — E2E and untargetable nodes |
| — | querySelector, CSS class selectors, XPath | Never |
Reaching for a lower-priority selector is usually an accessibility signal: if no role or label can address the element, users of assistive technology cannot address it either — fix the markup instead of the test.
skills/testing/visual-regression/SKILL.md.any responsesserver.resetHandlers() runs between testsfetch/axios added alongside MSW