Generates mocks, stubs, spies, and fakes for test dependency isolation. Supports Jest/Vitest/Sinon, pytest/unittest.mock, Go/gomock, and more.
npx claudepluginhub jeremylongshore/claude-code-plugins-plus-skills --plugin test-doubles-generatorThis skill is limited to using the following tools:
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.
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.
Creates stubs and mocking configurations for test automation, covering unit testing, integration testing, and frameworks like Jest and pytest. Triggers on 'stub creator' phrases.
Generates 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.
Share bugs, ideas, or general feedback.
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
}