asyncPopulate and custom object types
See original GitHub issueDescription:
I my application I use js-money package which allows to manage money easily. So, when I try to create a factory and Money
object as factory attribute it returns me a plain object instead of Money
Steps
- Define a factory
- Invoke
factory.build
and pass inbalance
propertyMoney
instance - Output
result.balance.constructor
Actual result
Shows Object
and all Money
methods are lost
Expected result:
Shows Money
Reproduction code:
const { factory, ObjectAdapter } = require('factory-girl');
const Money = require('js-money');
factory.setAdapter(new ObjectAdapter());
factory.define('Account', Object, {
name: factory.seq('name'),
balance: new Money(10, Money.USD)
});
async function run() {
const account = await factory.build('Account');
console.log(account.balance.constructor);
}
run();
Workaround:
The workaround is to use a function for custom object types:
factory.define('Account', Object, {
name: factory.seq('name'),
balance: () => new Money(10, Money.USD)
});
But this increases boilerplate and may become an issue when you want to pass result of one factory as properties into another factory.
Possible solution:
- Copy only plain objects, constructor of which is
Object
- Allow to pass an option/hook in
FactoryGirl
class that makes a decision which objects may be copied
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:14 (3 by maintainers)
Top Results From Across the Web
Understand Custom & Standard Objects - Trailhead - Salesforce
You can customize standard objects by adding custom fields, and you can add custom fields to your custom objects. Every field has a...
Read more >Custom Objects Events - Zendesk Developer Docs
Custom objects events track the user actions executed on object records and object types. The following actions trigger an event:.
Read more >Understanding Salesforce Standard and Custom Objects
Salesforce supports several different types of objects. There are standard objects, custom objects, external objects, platform events, ...
Read more >Custom object field types - Oracle Help Center
Custom object field types. Custom objects have one or more fields that store data associated with a custom object record. There is a...
Read more >Creating Salesforce Objects and Tabs - Standard and Custom
These objects can be standard objects or custom objects. You can define different types of relationships by creating custom relationship fields ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve pushed v5.0.0-beta.1, which doesn’t traverse into objects unless they’re instances of Object, so Dates and other types are preserved. Please give this version a go and let me know if this causes any other issues. It’s likely to cause some edge cases for a few people, but a few people have encountered issues with this, and I think the new behaviour is less unexpected.
I have been upgrading our test suite to
v5.0.0-beta.1
in order to fix the date issue. It’s working great 👍.