From aj-geddes-useful-ai-prompts-4
Creates and manages mocks, stubs, spies, and test doubles to isolate unit tests from external dependencies like databases, APIs, and services. Supports Jest, Python unittest.mock, and Mockito.
npx claudepluginhub joshuarweaver/cascade-code-languages-misc-1 --plugin aj-geddes-useful-ai-prompts-4This skill uses the workspace's default tool permissions.
- [Overview](#overview)
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.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Checks Next.js compilation errors using a running Turbopack dev server after code edits. Fixes actionable issues before reporting complete. Replaces `next build`.
Mocking and stubbing are essential techniques for isolating units of code during testing by replacing dependencies with controlled test doubles. This enables fast, reliable, and focused unit tests that don't depend on external systems like databases, APIs, or file systems.
Minimal working example:
// services/UserService.ts
import { UserRepository } from "./UserRepository";
import { EmailService } from "./EmailService";
export class UserService {
constructor(
private userRepository: UserRepository,
private emailService: EmailService,
) {}
async createUser(userData: CreateUserDto) {
const user = await this.userRepository.create(userData);
await this.emailService.sendWelcomeEmail(user.email, user.name);
return user;
}
async getUserStats(userId: string) {
const user = await this.userRepository.findById(userId);
if (!user) throw new Error("User not found");
const orderCount = await this.userRepository.getOrderCount(userId);
return { ...user, orderCount };
}
}
// ... (see reference guides for full implementation)
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Jest Mocking (JavaScript/TypeScript) | Jest Mocking (JavaScript/TypeScript) |
| Python Mocking with unittest.mock | Python Mocking with unittest.mock |
| Mockito for Java | Mockito for Java |
| Advanced Mocking Patterns | Advanced Mocking Patterns |