-
-
Notifications
You must be signed in to change notification settings - Fork 943
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
feat(helpers): add support for complex intermediate return types in fake method #2381
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## next #2381 +/- ##
==========================================
- Coverage 99.60% 99.60% -0.01%
==========================================
Files 2660 2786 +126
Lines 246345 252572 +6227
Branches 1086 1089 +3
==========================================
+ Hits 245375 251577 +6202
- Misses 943 968 +25
Partials 27 27
|
}); | ||
|
||
it('should return undefined if a method returns a complex object but the property is undefined', () => { | ||
expect(faker.helpers.fake('{{airline.airport.code}}')).toBe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently if a property is unknown on we receive an error:
Invalid module method or definition: person.abc
- faker.person.abc is not a function
- faker.definitions.person.abc is not an array
I would prefer if we could throw this error here as well and add a case for faker.person is a function but does not return an object with the property abc
. I'll gladly take suggestions on the phrasing.
); | ||
}); | ||
|
||
it('should be able to pass multiple dynamic templates with complex objects', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this test actually adds any value since we already have a test for an array argument:
faker/test/modules/helpers.spec.ts
Lines 1082 to 1089 in 604d52d
it('should be able to pass multiple dynamic templates', () => { | |
expect(faker.definitions.location.city_name).toContain( | |
faker.helpers.fake([ | |
'{{location.city_name}}', | |
'{{location.cityName}}', | |
]) | |
); | |
}); |
…types in fake method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a test that checks that if the fn didnt return a complex object and the property was requested that then an error is thrown.
Also I'm not sure about the current implementation.
E.g. Because it would break for {{airline.airport().iataCode}}
and it no longer supports it for 4 or deeper properties, but I'm not sure it has to.
Which of these do we expect to work A {{airline.airport().iataCode}} B {{airline.airport.iataCode}} C {{airline.airport.iataCode()}} |
I would expect A and B to work. |
Thanks for your contribution ❤️, we used it to create a new PR for this feature. Superseded by #2550 |
Fixes #1850
I started to add support for complex intermediate return types in the fake method of the helpers module as described in #1850.
Currently, it is a work in progress. I would like to get feedback from you.
I wrote a few tests and will add more in the next days, for example for locale data references.