From zenbu-powers
當在 React IT Gherkin 測試中進行「系統初始狀態設定」時,「只能」使用此指令。 使用 MSW server.use() 設定 mock API responses 作為測試的前置條件。
npx claudepluginhub zenbuapps/zenbu-powers --plugin zenbu-powersThis skill uses the workspace's default tool permissions.
Given 語句描述 **Aggregate 的存在狀態**,即定義系統中某些資料的初始值。
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Checks Next.js compilation errors using a running Turbopack dev server after code edits. Fixes actionable issues before reporting complete. Replaces `next build`.
Guides code writing, review, and refactoring with Karpathy-inspired rules to avoid overcomplication, ensure simplicity, surgical changes, and verifiable success criteria.
Share bugs, ideas, or general feedback.
Given 語句描述 Aggregate 的存在狀態,即定義系統中某些資料的初始值。
識別規則:
通用判斷:如果 Given 是在建立測試的初始資料狀態(而非執行動作),就使用此 Handler。
建立 Factory Test Data → 透過 server.use() 設定 MSW Handler → 使 Component fetch 到預設資料。
| aggregate-given | command(Given 用法) | |
|---|---|---|
| 目的 | 設定 MSW mock 回傳預設資料(繞過 UI 操作) | 透過 user-event 執行 UI 操作 |
| 層級 | MSW Handler 層 | UI 互動層 |
| 適用時機 | 純前置資料設定(「系統中有某些資料」) | 測試需要經過完整 UI 流程(「用戶已完成某操作」) |
| 語態 | 現在式/存在式(「有」「為」「包含」) | 過去式/完成式(「已訂閱」「已建立」) |
server.use() 註冊 MSW handler,回傳 factory datalet 變數Given 用戶 "Alice" 在課程 1 的進度為 70%,狀態為 "進行中"
import { http, HttpResponse } from 'msw';
import { server } from '@/test/mocks/server';
import { mockLessonProgress } from '@/test/factories';
// In beforeEach or at the start of it() block:
const lessonProgress = mockLessonProgress({
userId: 'alice-id',
lessonId: 1,
progress: 70,
status: 'IN_PROGRESS',
});
server.use(
http.get('/api/v1/lessons/:lessonId/progress', ({ params }) => {
return HttpResponse.json({
success: true,
data: lessonProgress,
});
})
);
Given 系統中有以下用戶:
| userId | name | email |
| 1 | Alice | alice@test.com |
| 2 | Bob | bob@test.com |
const users = [
mockUser({ id: '1', name: 'Alice', email: 'alice@test.com' }),
mockUser({ id: '2', name: 'Bob', email: 'bob@test.com' }),
];
server.use(
http.get('/api/v1/users', () => {
return HttpResponse.json({ success: true, data: users });
})
);
Given 用戶 "Alice" 已登入
And 課程 1 的名稱為 "物件導向基礎"
server.use(
http.get('/api/v1/auth/me', () => {
return HttpResponse.json({ success: true, data: mockUser({ name: 'Alice' }) });
}),
http.get('/api/v1/lessons/:lessonId', ({ params }) => {
return HttpResponse.json({
success: true,
data: mockLesson({ id: Number(params.lessonId), name: '物件導向基礎' }),
});
})
);
| 中文 | Enum Value | 情境 |
|---|---|---|
| 進行中 | IN_PROGRESS | 進度、狀態 |
| 已完成 | COMPLETED | 進度、狀態 |
| 未開始 | NOT_STARTED | 進度、狀態 |
| 已付款 | PAID | 訂單 |
| 待付款 | PENDING | 訂單 |
{ success: true, data: ... }let userId: string;