Forger Help

Quick Start

This guide walks through the first forged test: a service that stores students.

1. The type under test

interface Student { name: string; age: number; birthday: Date; }

There is nothing special about it — Forger works with interfaces, classes, and type aliases alike.

2. Forge instead of building

Before Forger, the test would start with stub data:

const student = { name: 'test', age: 20, birthday: new Date() }; // noise

With Forger it becomes:

import { Forger } from '@artstesh/forger'; describe('student.service', () => { it('save success', () => { const student = Forger.create<Student>()!; // const result = studentService.save(student); // expect(result).toBeTruthy(); }); });

Forger.create<Student>() returns a fully populated student: a random name, a random age, a random date. The test is now about the behavior of save — nothing else.

3. Pin what matters with createWith

When a concrete value is the point of the test, pin it:

it('rejects underage students', () => { const student = Forger.createWith<Student>() .with(s => s.age = 15) .result()!; // expect(studentService.save(student)).toBe(false); });

One with() call pins one property; everything else stays generated. Details in createWith.

4. Tune the generation

Numeric ranges, string length and charset, date windows, array sizes — all controlled by a single optional settings object:

const student = Forger.create<Student>({ numberMax: 100, stringLength: 8, arrayLength: 5, dateMin: new Date(2000, 0, 1), });

The full list of knobs lives in Settings.

5. What's next

  • How it works — the compile-time transformer and the runtime factories.

  • Supported types — what every type kind produces.

  • Cookbook — ready-made recipes for common test-data needs.

08 September 2026