fixture()

Creates a fixture definition.

Signature#

fixture<TResult, TArgs>(config: {
create: (
context: { [key: string]: PluginContext },
args: TArgs,
info: {
list: {
index: number,
size: number
}
}
) => MaybePromise<TResult>;
}) => (args?: TArgs) => Fixture<TResult>
  • create (required): A function that defines how to create a data model. This functions receives the following arguments:

Example#

interface PostArgs {
author: User;
}
export const postFixture = fixture<Post, PostArgs>({
create(context, args) {
const post = new Post({
title: context.faker.lorem.slug(),
body: context.faker.lorem.paragraphs(4),
author: args.author,
});
return post;
},
});
it("should be executable", async () => {
const post = await postFixture({ author: new User() }).execute();
});