DEV.co
Open-Source Testing · Typescript-TDD

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.

Source: GitHub — github.com/Typescript-TDD/ts-auto-mock
610
GitHub stars
16
Forks
TypeScript
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
RepositoryTypescript-TDD/ts-auto-mock
OwnerTypescript-TDD
Primary languageTypeScript
LicenseMIT — OSI-approved
Stars610
Forks16
Open issues34
Latest release3.7.4 (2024-08-24)
Last updated2025-05-26
Sourcehttps://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.

Quickstart

Get the ts-auto-mock source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/Typescript-TDD/ts-auto-mock.gitcd ts-auto-mock# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Unit testing with strict type safety

When you need to test TypeScript code with minimal boilerplate and want compiler-verified mock types that match your interfaces exactly, reducing test maintenance overhead.

TDD workflows with tsc-only pipelines

Projects using TypeScript directly with tsc compiler where rapid mock creation supports fast test-driven development cycles without custom mock factories.

Interface-heavy domains with many collaborators

Codebases with numerous dependencies and interfaces where automatic mock generation significantly reduces manual spy/stub setup code compared to hand-written fakes.

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.

SignalAssessment
MaintenanceStale
DocumentationAdequate
License clarityClear
Deployment complexityModerate
DEV.co fitGood
Assessment confidenceHigh
Security considerations

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.

Software development agency

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.co

Related 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?
No. Library explicitly supports tsc compiler only. TypeScript transformer plugins are not compatible with esbuild, swc, or webpack without native transformer support. You would need a different mocking solution.
Will ts-auto-mock work with future TypeScript versions?
Unknown. Project is no longer in active feature development. While bug fixes continue, TypeScript's major version releases may introduce breaking changes. Monitor releases and test upgrades carefully.
How do I customize mock values?
README and examples show auto-generated mocks use default/zero values. Library does not document property-level customization; you likely override manually post-creation or extend the mock object.
Is there a performance impact?
Operates at compile-time only; no runtime overhead. Compilation speed impact is not documented; review with your project's build benchmarks.

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.