Skip to content
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

Nested Factories #119

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Nested Factories #119

wants to merge 2 commits into from

Conversation

Gailbear
Copy link

I often find myself writing this code out in my codebase, so I figured I would attempt to contribute back. We've found it to be a huge timesaver for us, especially in terms of large nested objects, with large, nested component trees.

The main purpose is to be able to extend a factory as a nested factory easily (ParentFactory.extend(ChildFactory, 'child')) and be able to pass attributes and options for children easily into the parent factory. I settled on the double underscore convention (child__childAttr), as dot notation got messy, and nested objects conflicted with the ability to pass in attributes.

In addition to using this frequently in my own (unfortunately proprietary) codebase, I've also written tests here, and updated the readme. Please let me know if you need me to make any other adjustments.

- Add to the capability of `extend` by adding a second parameter, which
  is the name of an attribute to add this factory under
- Adds `attribute__childAttr` attributes to parent
- Adds `attribute__childOption` options to parent
- Removes `attribute__childAttr`s from the resulting output object
- Retains the old behavior if no attribute is given

- Add quite a few tests to ensure that it works
- Add documentation in the readme with examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant