-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subset of items for buildList should be build for each item #102
Comments
Thank you for reporting this and for the simple example and CodeSandbox. They were both very helpful in understanding the problem you're facing. This behavior is a consequence of the way builder functions, like So, basically, what is happening is: // returns a new userFactory that has "{ posts: [{id:1},{id:2},{id:3},{id:4},{id:5}] }" saved as "extra" params
const userFactoryWithPosts = userFactory.withPosts()
// To build the user, this takes the return object from the factory and then merges
// the stored "extra" params and then merges the build params ("{ id: 1 }") to
// construct the final object. Does not regenerate extra params
userFactoryWithPosts.build({ id: 1 }); This would be one way to get your desired behavior, though it's cumbersome (Sandbox): const users = [
userFactory.withPosts().build(),
userFactory.withPosts().build(),
userFactory.withPosts().build(),
userFactory.withPosts().build(),
userFactory.withPosts().build()
]; Ideally, we could instead run the builder functions dynamically at build time (i.e. instead of storing |
No problem at all! If you can point me where I can help you with it, I can try to create PR for this. I found the place where Thanks in advance! |
@vanatd-printify How were you able to achieve it? I hit the exact same problem and since I use a circularReplacer function when I |
Same problem |
Description
First of all, thank you guys for your hard work, this is really cool lib!
During the integration with the fishery, we found one behavior that seems wrong.
Imagine that we have Users with Posts and I what to generate a list of users with random posts, let's say 5 users with 5 posts.
To make it more useful I've done it like this:
So after I created a list of users I expected to have 25 different posts, but I have 5 users with the same 5 posts.
To Reproduce
CodeSandbox with a failing test
The text was updated successfully, but these errors were encountered: