You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a great library that I have found very useful! However, I often like to create lists of objects with unique attributes. Unfortunately, when attributes are set using buildList the sequences no longer work. All the objects have identical values, even if they are sequences or calculated using functions. This is because the attributes have been mutated and include all the attributes of the first object. It appears that these attributes have been passed in, and are set on all subsequent objects. This only happens if attributes are specified, because if attributes are not specified the attribute variable here is set to a new, empty object for each object created.
To reproduce the error:
Factory.define('test')
.sequence('id')
.attr('random', function() {
return Math.floor(Math.random() * 100);
})
.attr('constant', 'same');
// this produces 4 objects with different ids and 'random' attributes
Factory.buildList('test', 4);
// this produces 4 objects with identical attributes
Factory.buildList('test', 4, {constant: 'different'});
I am submitting a pull request with a simple fix
The text was updated successfully, but these errors were encountered:
This is a great library that I have found very useful! However, I often like to create lists of objects with unique attributes. Unfortunately, when attributes are set using buildList the sequences no longer work. All the objects have identical values, even if they are sequences or calculated using functions. This is because the attributes have been mutated and include all the attributes of the first object. It appears that these attributes have been passed in, and are set on all subsequent objects. This only happens if attributes are specified, because if attributes are not specified the attribute variable here is set to a new, empty object for each object created.
To reproduce the error:
I am submitting a pull request with a simple fix
The text was updated successfully, but these errors were encountered: