mocking-assistant
Creates stable mocks for APIs, services, and UI components using MSW (Mock Service Worker), fixture conventions, and example patterns. Use for "API mocking", "MSW", "test mocks", or "service mocking".
Best use case
mocking-assistant is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Creates stable mocks for APIs, services, and UI components using MSW (Mock Service Worker), fixture conventions, and example patterns. Use for "API mocking", "MSW", "test mocks", or "service mocking".
Teams using mocking-assistant should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/mocking-assistant/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How mocking-assistant Compares
| Feature / Agent | mocking-assistant | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Creates stable mocks for APIs, services, and UI components using MSW (Mock Service Worker), fixture conventions, and example patterns. Use for "API mocking", "MSW", "test mocks", or "service mocking".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Mocking Assistant
Create reliable mocks for APIs and services in tests.
## MSW API Mocking
```typescript
// mocks/handlers.ts
import { http, HttpResponse } from "msw";
export const handlers = [
// GET endpoint
http.get("/api/users/:id", ({ params }) => {
const { id } = params;
return HttpResponse.json({
id,
name: "John Doe",
email: "john@example.com",
});
}),
// POST endpoint
http.post("/api/users", async ({ request }) => {
const body = await request.json();
return HttpResponse.json(
{
id: Math.random().toString(),
...body,
createdAt: new Date().toISOString(),
},
{ status: 201 }
);
}),
// Error response
http.get("/api/products/:id", ({ params }) => {
const { id } = params;
if (id === "404") {
return HttpResponse.json({ error: "Product not found" }, { status: 404 });
}
return HttpResponse.json({
id,
name: "MacBook Pro",
price: 2499.99,
});
}),
// Delayed response
http.get("/api/slow-endpoint", async () => {
await delay(2000);
return HttpResponse.json({ data: "Slow response" });
}),
];
```
## MSW Setup
```typescript
// mocks/server.ts
import { setupServer } from "msw/node";
import { handlers } from "./handlers";
export const server = setupServer(...handlers);
// tests/setup.ts
import { beforeAll, afterEach, afterAll } from "vitest";
import { server } from "../mocks/server";
beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
```
## Fixture Conventions
```typescript
// mocks/fixtures/users.ts
export const userFixtures = {
admin: {
id: "1",
email: "admin@example.com",
name: "Admin User",
role: "ADMIN",
},
customer: {
id: "2",
email: "customer@example.com",
name: "Customer User",
role: "USER",
},
guest: {
id: "3",
email: "guest@example.com",
name: "Guest User",
role: "GUEST",
},
};
// mocks/fixtures/products.ts
export const productFixtures = {
laptop: {
id: "100",
name: "MacBook Pro",
price: 2499.99,
stock: 10,
category: "Electronics",
},
phone: {
id: "101",
name: "iPhone 15",
price: 999.99,
stock: 50,
category: "Electronics",
},
outOfStock: {
id: "102",
name: "Sold Out Item",
price: 499.99,
stock: 0,
category: "Electronics",
},
};
// Usage in handlers
http.get("/api/users/:id", ({ params }) => {
const user = Object.values(userFixtures).find((u) => u.id === params.id);
if (!user) {
return HttpResponse.json({ error: "User not found" }, { status: 404 });
}
return HttpResponse.json(user);
});
```
## Test-Specific Mocks
```typescript
// tests/components/UserProfile.test.tsx
import { server } from "../mocks/server";
import { http, HttpResponse } from "msw";
test("should display user profile", async () => {
// Override handler for this test
server.use(
http.get("/api/users/123", () => {
return HttpResponse.json({
id: "123",
name: "Test User",
email: "test@example.com",
});
})
);
render(<UserProfile userId="123" />);
await waitFor(() => {
expect(screen.getByText("Test User")).toBeInTheDocument();
});
});
test("should handle API error", async () => {
// Mock error response
server.use(
http.get("/api/users/123", () => {
return HttpResponse.json({ error: "Server error" }, { status: 500 });
})
);
render(<UserProfile userId="123" />);
await waitFor(() => {
expect(screen.getByText("Failed to load user")).toBeInTheDocument();
});
});
```
## Service Mocking
```typescript
// src/services/paymentService.ts
export interface PaymentService {
processPayment(amount: number, cardToken: string): Promise<PaymentResult>;
refund(transactionId: string): Promise<void>;
}
// mocks/services/mockPaymentService.ts
export class MockPaymentService implements PaymentService {
async processPayment(
amount: number,
cardToken: string
): Promise<PaymentResult> {
// Simulate successful payment
if (cardToken.startsWith("tok_success")) {
return {
transactionId: "txn_" + Math.random().toString(36),
status: "success",
amount,
};
}
// Simulate failed payment
if (cardToken.startsWith("tok_fail")) {
throw new Error("Payment failed");
}
// Simulate slow payment
await new Promise((resolve) => setTimeout(resolve, 2000));
return {
transactionId: "txn_" + Math.random().toString(36),
status: "success",
amount,
};
}
async refund(transactionId: string): Promise<void> {
// Mock refund
console.log(`Refunding transaction: ${transactionId}`);
}
}
// tests/checkout.test.ts
const mockPaymentService = new MockPaymentService();
test("should process payment successfully", async () => {
const result = await mockPaymentService.processPayment(
100,
"tok_success_123"
);
expect(result.status).toBe("success");
expect(result.transactionId).toBeDefined();
});
```
## Function Mocking with Vitest
```typescript
// src/utils/analytics.ts
export const trackEvent = (event: string, data: any) => {
// Send to analytics service
};
// tests/component.test.ts
import { vi } from "vitest";
import * as analytics from "@/utils/analytics";
test("should track button click", () => {
// Mock function
const trackEventSpy = vi.spyOn(analytics, "trackEvent");
render(<Button onClick={handleClick} />);
fireEvent.click(screen.getByRole("button"));
expect(trackEventSpy).toHaveBeenCalledWith("button_click", {
buttonId: "submit",
});
});
```
## Date/Time Mocking
```typescript
// tests/date-sensitive.test.ts
import { vi } from "vitest";
test("should show correct greeting based on time", () => {
// Mock date to morning
vi.setSystemTime(new Date("2024-01-01 09:00:00"));
render(<Greeting />);
expect(screen.getByText("Good morning!")).toBeInTheDocument();
// Mock date to evening
vi.setSystemTime(new Date("2024-01-01 19:00:00"));
render(<Greeting />);
expect(screen.getByText("Good evening!")).toBeInTheDocument();
// Restore real time
vi.useRealTimers();
});
```
## Module Mocking
```typescript
// src/lib/database.ts
export const db = {
user: {
findById: (id: string) => {
// Real database query
},
},
};
// tests/mocks/database.ts
export const mockDb = {
user: {
findById: vi.fn((id: string) => ({
id,
name: "Mock User",
email: "mock@example.com",
})),
},
};
// tests/userService.test.ts
vi.mock("@/lib/database", () => ({
db: mockDb,
}));
test("should fetch user from database", async () => {
const user = await userService.getUser("123");
expect(mockDb.user.findById).toHaveBeenCalledWith("123");
expect(user.name).toBe("Mock User");
});
```
## GraphQL Mocking
```typescript
// mocks/graphql-handlers.ts
import { graphql, HttpResponse } from "msw";
export const graphqlHandlers = [
graphql.query("GetUser", ({ variables }) => {
return HttpResponse.json({
data: {
user: {
id: variables.id,
name: "John Doe",
email: "john@example.com",
},
},
});
}),
graphql.mutation("CreateUser", ({ variables }) => {
return HttpResponse.json({
data: {
createUser: {
id: Math.random().toString(),
...variables.input,
},
},
});
}),
];
```
## Best Practices
1. **Use MSW for HTTP**: More realistic than mocking fetch
2. **Centralize fixtures**: Single source of truth
3. **Test-specific overrides**: Override defaults per test
4. **Mock at boundaries**: Services, APIs, not internals
5. **Realistic data**: Fixtures should match production
6. **Error scenarios**: Test failure cases
7. **Timing control**: Mock delays for loading states
## Output Checklist
- [ ] MSW handlers created
- [ ] Fixture conventions established
- [ ] Common fixtures defined
- [ ] Test-specific mock overrides
- [ ] Service mocks implemented
- [ ] Function spies used appropriately
- [ ] Date/time mocking when needed
- [ ] Error scenarios mocked
- [ ] GraphQL mocks (if applicable)
- [ ] Documentation for mock usageRelated Skills
music-assistant
Control Home Assistant Music Assistant - browse library, search, play, manage preferences and moods.
lead-research-assistant
Researches and identifies potential customers, leads, and business opportunities for your product or service. Analyzes your offering, finds relevant companies and decision makers, provides contact information, and suggests outreach strategies. Use when looking for leads, researching target customers, identifying decision makers, or planning sales outreach.
kumo-assistant
Kumo development assistant for MySQL database management tool. Use when working on Kumo features, understanding architecture, writing tests, or navigating the codebase. Helps with React components, API endpoints, database features, and Electron app development.
code-review-assistant
Comprehensive code review assistant that analyzes code for security vulnerabilities, performance issues, and code quality. Use when reviewing pull requests, conducting code audits, or analyzing code changes. Supports Python, JavaScript/TypeScript, and general code patterns. Includes automated analysis scripts and structured checklists.
code-assistant
Expert coding assistant for writing, reviewing, and debugging code across multiple languages
awesome-copilot-root-kusto-assistant
Expert KQL assistant for live Azure Data Explorer analysis via Azure MCP server Use when: the task directly matches kusto assistant responsibilities within plugin awesome-copilot-root. Do not use when: a more specific framework or task-focused skill is clearly a better match.
assistant-behavior-rules
AI assistant behavior rules including response formatting and interaction patterns
ai-assistants
AI-powered development tools configuration and usage
ai-assistant-chat
Build self-hosted AI chat assistants using CopilotKit + LangGraph. Use when implementing conversational AI interfaces with agentic backends, streaming responses, shared state between frontend and backend, or generative UI. This pattern uses NO hosted services - both CopilotKit runtime and LangGraph agent run on your own infrastructure. Triggers on requests to build chat interfaces, AI assistants, conversational agents, or integrate LangGraph with React frontends.
Machine Vision Assistant
Comprehensive MV learning assistant for industrial computer vision applications. Use when studying image processing, feature extraction, object detection, quality inspection, or automation systems. Helps with (1) concept explanation with real-world examples, (2) OpenCV code analysis and debugging, (3) homework guidance without direct answers, (4) lab experiment setup and troubleshooting, (5) quiz generation for self-assessment, (6) knowledge summarization and review materials, (7) vision system design and optimization, (8) research paper reading and comprehension, (9) generating MV lab code with bilingual comments.
rails-upgrade-assistant
Analyzes Rails applications and generates comprehensive upgrade reports with breaking changes, deprecations, and step-by-step migration guides for Rails 7.0 through 8.1.1. Use when upgrading Rails applications, planning multi-hop upgrades, or querying version-specific changes.
paper-writing-assistant
Assist in drafting research papers and meeting notes, enforcing academic rigor and formatting.