Quickstart
1. Install Fluse#
- yarn
 - npm
 
npm install fluse --save-dev
yarn add -D fluse
2. Initialize#
import { fluse } from "fluse";
export const { fixture, scenario } = fluse();
3. Define some fixtures for your models#
import faker from "faker";
import { Comment } from "./model/Comment";
import { Post } from "./model/Post";
import { User } from "./model/User";
export const userFixture = fixture<User>({
  create() {
    return new User({
      userName: faker.internet.userName(),
    });
  },
});
interface CommentArgs {
  author: User;
}
export const commentFixture = fixture<Comment, CommentArgs>({
  create(_ctx, args) {
    return new Comment({
      message: faker.lorem.slug(),
      author: args.author,
    });
  },
});
interface PostArgs {
  author: User;
  comments?: Comment[];
}
export const postFixture = fixture<Post, PostArgs>({
  create(_ctx, args) {
    return new Post({
      title: faker.lorem.slug(),
      body: faker.lorem.paragraphs(4),
      author: args.author,
      comments: args.comments,
    });
  },
});
3. Supercharge your tests!#
it("should create a single post", async () => {
  const post = await postFixture({
    author: userFixture.asArg(),
  }).execute();
  expect(singlePost).toBeDefined();
});
it("should create many posts", async () => {
  const posts = await postFixture({
    author: userFixture(),
  })
    .list(3)
    .execute();
  expect(posts).toBeDefined();
});
it("should create a complex scenario", async () => {
  const { bob, alice, bobsPosts, alicesPosts } = await scenario()
    .with("bob", userFixture())
    .with("alice", userFixture())
    .with("bobsPosts", ({ bob }) =>
      postFixture({
        author: bob,
        comments: commentFixture({
          author: userFixture(),
        }).list(3),
      }).list(5)
    )
    .with("alicesPosts", ({ alice }) =>
      postFixture({
        author: alice,
        comments: commentFixture({
          author: userFixture(),
        }).list(3),
      }).list(5)
    )
    .compose()
    .execute();
  expect(bob).toBeDefined();
  expect(alice).toBeDefined();
  expect(bobsPosts).toHaveLength(5);
  expect(alicesPosts).toHaveLength(5);
});