pnpm add -D @factory-js/factory
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.