Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Expose the number in the list of the current instance in a createList or buildList scenario #101

Open
jjm340 opened this issue May 9, 2022 · 0 comments

Comments

@jjm340
Copy link

jjm340 commented May 9, 2022

Is your feature request related to a problem? Please describe.
I'd like to be able to know which item in the list is being built if a particular factory is called with createList or buildList.

Describe the solution you'd like
I'd like the value i in this code:

buildList(
    number: number,
    params?: DeepPartial<T>,
    options: BuildOptions<T, I> = {},
  ): T[] {
    let list: T[] = [];
    for (let i = 0; i < number; i++) {
      list.push(this.build(params, options));
    }

    return list;
  }

Exposed to the factory so I could do something where I build a set of objects with monotonically decreasing dates, for example. My use case is I wanted a set of objects to be built with a date field that was today's date minus i day(s).

Describe alternatives you've considered
I did a workaround where I reset the factory's sequence number in between test runs which works, but it feels like having the option to know the relative sequence number AND the i value from above would be awesome and relatively simple.

Additional context
Let me know if anything is unclear about my request.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant