Skip to content

factory-js/factory-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4c26afa Β· May 11, 2025
Dec 14, 2024
May 10, 2025
Mar 12, 2024
Apr 6, 2025
May 11, 2025
Mar 12, 2024
Mar 12, 2024
Mar 12, 2024
Apr 6, 2025
Jun 25, 2024
Mar 12, 2024
Mar 12, 2024
Jul 15, 2024
Mar 12, 2024
Sep 16, 2024
Mar 14, 2024
Mar 7, 2025
Dec 14, 2024
Jun 24, 2024
Jun 24, 2024
May 10, 2025
May 11, 2025
Mar 24, 2024
Dec 14, 2024
Apr 23, 2024
Jun 25, 2024

Repository files navigation

FactoryJS

The object generator for testing.

coverage npm bundle size

Documentation・Contributing Guide

Features

  • βœ… Type Safety - It helps prevent configuration errors and typos.
  • βš™οΈ Highly Functional - You can define variables, traits, and properties that depend on other properties.
  • πŸͺΆ Lightweight - It is very lightweight as it does not depend on any other packages.
  • πŸ“¦ ORM-Friendly API - Designed to be used also with ORMs like Prisma and Drizzle.

Quick Start

  1. Install FactoryJS.
pnpm add -D @factory-js/factory
  1. Define a factory and use it in your tests, database seeds, etc.
import { factory } from "@factory-js/factory";

// Define the factory
const userFactory = factory.define({
  props: {
    firstName: () => "John",
    lastName: () => "Doe",
    role: () => "guest",
  },
  vars: {},
});

describe("when a user is admin", () => {
  it("returns true", async () => {
    const user = await userFactory(db)
      .props({ role: () => "admin" }) // Override role to admin
      .build();
    expect(isAdmin(user)).toBe(true);
  });
});

To learn more about FactoryJS, check the Documentation.

License

MIT