Auto-Generated Test Data for TypeScript
Forger is a lightweight library that forges fully populated objects of any TypeScript type. A single call — Forger.create<T>() — returns a realistic fake with every property filled in, so your tests contain only the data that really matters.
1. The problem Forger solves
Test code drowns in data. Before anything can be asserted, a test has to build the object under test — and every object it references:
builders and factory helpers pile up next to the production code;
test bodies are littered with literals that mean nothing to the reader;
every new field in a class breaks dozens of hand-written stubs;
dummy values like
name: 'test'mislead readers into thinking the data matters.
The result: tests are hard to write and harder to read, while the important part — the assertion — gets lost in the noise.
2. How Forger changes the picture
Forger generates the noise for you. Any type — interface, class, primitive, enum, array, tuple, function, union, generic — is forged automatically:
The test now shows what is important — the service call and the assertion. The data is present, valid, and random, exactly as test data should be.
Need a concrete value here and there? Pin it with createWith:
3. Core concepts
Concept | Description | Link to section |
|---|---|---|
Forger.create | Forge a fully populated value of any type. | |
Forger.createWith | Forge a value and pin specific properties to concrete values. | |
Type support | Primitives, dates, enums, literals, unions, arrays, tuples, functions. | |
Objects & generics | Interfaces, classes, inheritance chains, generic types, circular refs. | |
SpoofSettings | Tune how numbers, strings, dates, and arrays are generated. | |
Compile-time pipeline | A TypeScript transformer feeds type info to the runtime factories. |
4. Quick example
Everything is populated: id is a number, createdAt a date, items an array of strings, customer a nested object — and status is pinned to the exact value the test is about.
5. Why choose Forger?
Any type, one call — from
stringto deeply nested generics with circular references.Truly type-safe — the type is resolved at compile time by a TypeScript transformer, not guessed from runtime objects.
No setup surface — no builders, no fixtures, no registration; just call
create<T>().Tunable generation — ranges, lengths, and charsets through a single settings object.
Zero runtime dependencies — nothing but TypeScript in your peer dependencies.
Framework-agnostic — works with Jest, Karma, Angular, Webpack, or plain
tscbuilds.
6. Next steps
Install and wire up the transformer in Installation.
Write your first forged test in Quick Start.
Understand the machinery in How it works.
Look up what your types produce in Supported types.
Learn the sharp edges in Caveats.
Forger keeps your tests about behavior — not about data.