reviewing-testability
Testable code design patterns for TypeScript/React applications. Triggers: テスタビリティ, testability, テスト可能, テストしやすい, モック, mock, 純粋関数, pure function, 依存性注入, dependency injection, DI, 副作用, side effect, 副作用分離, テスト困難, hard to test.
When & Why to Use This Skill
This Claude skill specializes in auditing TypeScript and React codebases to improve testability and architectural integrity. It identifies common anti-patterns such as tight coupling, hidden side effects, and hardcoded dependencies, providing actionable refactoring advice to implement Dependency Injection (DI) and pure functional logic. By ensuring code is 'mock-friendly' and decoupled, it significantly reduces the complexity of writing unit tests and improves long-term maintainability.
Use Cases
- Refactoring React components to extract 'fetch' calls and side effects into injectable services, enabling easier unit testing without complex network mocks.
- Identifying and replacing direct class instantiations (new Service()) with constructor injection to facilitate better inversion of control.
- Decoupling business logic from global configurations or system clocks (e.g., Date.now()) by passing them as explicit parameters for predictable test results.
- Streamlining bloated test suites by detecting deep mock chains and suggesting architectural simplifications to keep test setups under 10 lines.
- Automating the review process for pull requests to ensure new code adheres to testable design patterns and SOLID principles.
| name | reviewing-testability |
|---|---|
| description | > |
| allowed-tools | [Read, Grep, Glob, Task] |
| agent | testability-reviewer |
| context | fork |
| user-invocable | false |
Testability Review
Detection
| ID | Pattern | Fix |
|---|---|---|
| TE1 | Direct import { db } usage |
Inject dependency as parameter |
| TE1 | new Service() inside class |
Constructor injection |
| TE2 | fetch() inside component |
Extract to hook/service, inject |
| TE2 | Mixed side effects + logic | Separate pure/impure |
| TE3 | Deep mock chains | Simplify dependencies |
| TE4 | Global config access |
Pass config as prop/parameter |
| TE4 | Date.now() in logic |
Inject clock/time provider |
| TE5 | Tight coupling | Depend on abstractions (DIP) |
Criteria
Test setup < 10 lines. No deep mock chains. Dependencies explicit.
References
| Topic | File |
|---|---|
| DI | references/dependency-injection.md |
| Pure | references/pure-functions.md |
| Mocking | references/mock-friendly.md |