From aj-geddes-useful-ai-prompts-4
Creates and manages mocks, stubs, and spies for isolating unit tests, with reference guides for Jest, Mockito, and unittest.mock.
How this skill is triggered — by the user, by Claude, or both
Slash command
/aj-geddes-useful-ai-prompts-4:mocking-stubbingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- [Overview](#overview)
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 |
npx claudepluginhub joshuarweaver/cascade-code-languages-misc-1 --plugin aj-geddes-useful-ai-prompts-4Generates mocks, stubs, spies, and fakes for dependency isolation in tests. Supports Jest, Sinon, Python unittest.mock, Go interfaces, and testdouble.js.
Creates mock APIs and services for testing using MSW, Nock, or custom mock servers, with typed factories and request interception patterns.
Guides stub creator operations for test automation, including mocking, unit/integration testing, and test framework configuration.