ts-auto-mock
ts-auto-mock is a TypeScript transformer that automatically generates mock objects from interfaces and classes for testing, eliminating manual fake creation. It integrates directly into the TypeScript compilation process and supports major testing frameworks via companion libraries.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | Typescript-TDD/ts-auto-mock |
| Owner | Typescript-TDD |
| Primary language | TypeScript |
| License | MIT — OSI-approved |
| Stars | 610 |
| Forks | 16 |
| Open issues | 34 |
| Latest release | 3.7.4 (2024-08-24) |
| Last updated | 2025-05-26 |
| Source | https://github.com/Typescript-TDD/ts-auto-mock |
What ts-auto-mock is
A compile-time TypeScript transformer that uses reflection to generate type-safe mock instances from type definitions. It operates as a custom transformer in the tsc compilation pipeline, generating default-valued mock objects without requiring manual setup or configuration per type.
Get the ts-auto-mock source
Clone the repository and explore it locally.
git clone https://github.com/Typescript-TDD/ts-auto-mock.gitcd ts-auto-mock# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Configure TypeScript compiler with custom transformer plugin in tsconfig.json; requires tsc as build tool.
- Mocks generate with default/zero values (empty strings, 0, false); verify these defaults align with your test logic or add manual overrides.
- Install companion jest-ts-auto-mock or jasmine-ts-auto-mock if using those frameworks; base library works standalone.
- Review test strategy to avoid over-mocking; library makes mock creation effortless but does not enforce strategic test-double usage.
- Type changes in interfaces automatically reflect in mocks at compile time; no runtime discovery or late binding.
When to avoid it — and what to weigh
- Using non-tsc build tools — Project explicitly states transformers only work with tsc. If using esbuild, swc, webpack, or other bundlers without tsc transformer support, this library will not function.
- Over-reliance on test doubles risks your test value — README acknowledges test doubles are 'double-edge sword' and can reduce test value if overused. If your testing strategy requires careful, selective mocking, auto-generation may encourage excessive doubles.
- Complex custom mock behavior required — If mocks need special validation logic, custom getters/setters, or event tracking beyond default values, the automatic approach will likely require overrides or supplementary manual setup.
- Projects requiring cutting-edge maintenance — Explicitly archived from new feature development. Only bug fixes and security patches are planned; no roadmap for new capabilities or TypeScript version adaptation.
License & commercial use
MIT License (permissive, OSI-approved). Allows commercial use, modification, and distribution with minimal restrictions (retain license notice and copyright).
MIT License explicitly permits commercial use. No licensing fees or attribution requirements beyond retaining the license text. Review your internal IP/usage policies, but the license itself poses no commercial barriers.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Stale |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Moderate |
| DEV.co fit | Good |
| Assessment confidence | High |
No security audit data provided. Library operates at compile-time only (no runtime injection). Typical TypeScript transformer attack surface includes build-time code injection if tsconfig.json is compromised. Requires same security posture as TypeScript compiler. Monitor npm package for vulnerability disclosures.
Alternatives to consider
jest.mock() / jest.spyOn()
Built-in Jest mocking requires manual setup per test but offers fine-grained control and works with all bundlers. No transformer dependency.
sinon.js / testdouble
Framework-agnostic, runtime mocking libraries with extensive spy/stub features. Work in any build pipeline but require more boilerplate than auto-mock.
MSW (Mock Service Worker)
HTTP-level mocking; ideal if mocking external APIs rather than internal types. Decouples from TypeScript transformer complexity.
Build on ts-auto-mock with DEV.co software developers
If you use tsc compiler and want to reduce manual mock boilerplate, evaluate ts-auto-mock against your test strategy. Verify transformer plugin compatibility in your build first. For non-tsc pipelines (esbuild, swc), choose an alternative mocking library.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
ts-auto-mock FAQ
Can I use ts-auto-mock with esbuild or webpack?
Will ts-auto-mock work with future TypeScript versions?
How do I customize mock values?
Is there a performance impact?
Work with a software development agency
DEV.co helps companies turn open-source tools like ts-auto-mock into production software. Our software development services cover the full lifecycle — architecture, web development, integration, and maintenance — delivered by software developers and web developers who ship. Engage our software development agency to implement or customize it for your open-source testing stack.
Assess ts-auto-mock fit for your codebase
If you use tsc compiler and want to reduce manual mock boilerplate, evaluate ts-auto-mock against your test strategy. Verify transformer plugin compatibility in your build first. For non-tsc pipelines (esbuild, swc), choose an alternative mocking library.