Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/factory-js/factory-js

🏭 The object generator for testing.
https://github.com/factory-js/factory-js

drizzle-orm dummy-data e2e-testing factory factory-bot fixture integration-testing jest mock playwright prisma seed seeding t3-stack test testing unit-testing vitest

Last synced: 3 days ago
JSON representation

🏭 The object generator for testing.

Awesome Lists containing this project

README

        


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.

```sh
pnpm add -D @factory-js/factory
```

2. Define a factory and use it in your tests, database seeds, etc.

```ts
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](https://factory-js.github.io/).

## License

[MIT](https://github.com/factory-js/factory-js/blob/main/LICENSE)