Generate test doubles (mocks, stubs, spies, fakes) for unit testing
Generates test doubles (mocks, stubs, spies, fakes) for unit testing with framework-specific implementations.
/plugin marketplace add jeremylongshore/claude-code-plugins-plus/plugin install test-doubles-generator@claude-code-plugins-plusGenerate appropriate test doubles (mocks, stubs, spies, fakes, dummies) for unit testing based on the testing framework and dependencies being tested.
Analyze Dependencies
Generate Mocks
Generate Stubs
Generate Spies
When invoked, you should:
## Test Doubles Generated for: [Component]
### Dependencies Identified: [N]
#### Dependency: [Name]
**Type:** [API / Database / Service / File System]
**Test Double:** [Mock / Stub / Spy / Fake]
**Rationale:** [Why this type]
**Implementation:**
\`\`\`javascript
// Mock for [Name]
const mock[Name] = {
methodName: jest.fn()
.mockResolvedValueOnce([success response])
.mockRejectedValueOnce(new Error('[error]')),
anotherMethod: jest.fn().mockReturnValue([value])
};
\`\`\`
**Usage in Tests:**
\`\`\`javascript
describe('[Component]', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should [behavior]', async () => {
// Arrange
mock[Name].methodName.mockResolvedValue([data]);
// Act
const result = await componentUnderTest.action();
// Assert
expect(mock[Name].methodName).toHaveBeenCalledWith([expected args]);
expect(result).toEqual([expected result]);
});
it('should handle errors', async () => {
// Arrange
mock[Name].methodName.mockRejectedValue(new Error('[error]'));
// Act & Assert
await expect(componentUnderTest.action()).rejects.toThrow('[error]');
});
});
\`\`\`
### Test Data Fixtures
\`\`\`javascript
const fixtures = {
validData: { /* ... */ },
invalidData: { /* ... */ },
edgeCases: { /* ... */ }
};
\`\`\`
### Next Steps
- [ ] Implement generated test doubles
- [ ] Write test cases using doubles
- [ ] Verify test coverage
- [ ] Refactor for reusability
Mock: Behavior verification, tracks calls and arguments Stub: State verification, returns predefined responses Spy: Wraps real object, tracks interactions Fake: Working implementation with shortcuts (in-memory DB) Dummy: Placeholder objects, not used in test