Generates mocks, stubs, spies, and fakes for test dependency isolation. Supports Jest/Vitest/Sinon, pytest/unittest.mock, Go/gomock, and more.
How this skill is triggered — by the user, by Claude, or both
Slash command
/test-doubles-generator:generating-test-doublesThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Generate mocks, stubs, spies, and fakes to isolate units under test from external dependencies. Supports Jest mocks, Sinon.js stubs, Python unittest.mock, Go interfaces, and testdouble.js patterns.
Generate mocks, stubs, spies, and fakes to isolate units under test from external dependencies. Supports Jest mocks, Sinon.js stubs, Python unittest.mock, Go interfaces, and testdouble.js patterns.
strict mode enabled for type-safe mocks (if applicable)__mocks__/, test/doubles/, testutil/).jest.mock(), @patch, constructor injection, or Go interface substitution).tsc --noEmit or equivalent.__mocks__ auto-mock modules where applicable| Error | Cause | Solution |
|---|---|---|
TypeError: X is not a function | Mock missing a method from the real interface | Regenerate the double from the current interface definition; add the missing method |
| Mock leaking between tests | Shared mock state not reset in afterEach | Add jest.restoreAllMocks() or sinon.restore() in teardown hooks |
| Type mismatch on mock return value | Return type does not match interface contract | Use as ReturnType<typeof fn> or update the mock factory to return the correct type |
| Spy not recording calls | Spy created after the function was already bound | Create spies before the module under test imports the dependency |
| Over-mocking hides real bugs | Too many layers replaced with fakes | Limit mocks to true external boundaries (I/O, network); let pure logic run unmocked |
Jest mock factory for a UserRepository:
// __mocks__/userRepository.ts
export const createMockUserRepo = () => ({
findById: jest.fn().mockResolvedValue({ id: '1', name: 'Test User' }),
save: jest.fn().mockResolvedValue(undefined),
delete: jest.fn().mockResolvedValue(true),
});
Python unittest.mock patch for an HTTP client:
from unittest.mock import patch, MagicMock
@patch('myapp.client.requests.get')
def test_fetch_data(mock_get):
mock_get.return_value = MagicMock(status_code=200, json=lambda: {"key": "value"}) # HTTP 200 OK
result = fetch_data("https://api.example.com/data")
assert result == {"key": "value"}
mock_get.assert_called_once()
Go interface-based fake:
type FakeStore struct {
data map[string]string
}
func (f *FakeStore) Get(key string) (string, error) {
v, ok := f.data[key]
if !ok { return "", ErrNotFound }
return v, nil
}
npx claudepluginhub jeremylongshore/claude-code-plugins-plus-skills --plugin test-doubles-generatorGenerates PHPUnit test doubles (stubs, mocks, fakes, spies) for PHP 8.4. Selects type based on needs like verifying interactions, canned responses, or simplified real behavior.
Choosing between mocks, stubs, fakes, spies, and dummies based on testing needs.
Generates test suites with unit, integration, and e2e tests, proper mocking strategies, and edge case coverage. Works with any language/framework.