Forger Help

Enums

Enum type arguments are forged as a random member of the enum. Both numeric and string enums are supported, and every member — including the one valued 0 — is reachable.

Numeric enums

enum Status { Draft, // 0 Published, // 1 Archived, // 2 } const status = Forger.create<Status>()!; // Status.Published — or any other member, rolled at runtime

Each call rolls independently, so a Status[] array typically contains different members. The member with the numeric value 0 participates in the roll like any other.

String enums

enum Kind { User = 'user', Admin = 'admin', } const kind = Forger.create<Kind>()!; // 'user' or 'admin' — a real member of the enum

The forged value is the member's value, not its name, and membership in Object.values(Kind) always holds — safe for equality checks against enum constants.

Explicit values

Explicit numbering works the same way as auto-incremented:

enum Priority { Low = 1, High = 5, } const priority = Forger.create<Priority>()!; // 1 or 5

Pinning a member

When a test is specifically about one member, pin it with createWith:

const account = Forger.createWith<Account>() .with(a => a.kind = Kind.Admin) .result()!;

Enums vs literal unions

Both now forge correct members for every call. The choice is modeling, not behavior:

Literal union

Enum

Random member per call

yes

yes

Falsy members (0, '')

reachable

reachable

Enum API (Status.Draft)

no

yes

Needs a declaration statement

no (inline allowed)

yes

Keep enums where production code benefits from the enum API; use literal unions for inline constraints in test doubles.

08 September 2026