Unionized
Unionized is a factory library for setting up JavaScript objects as test data. Compare to the factory_girl Ruby gem by thoughtbot.
Links
Examples
Define a factory:
var humanFactory = unionized.factory({
name: {
first: unionized.enum(['Azrael', 'Bastiaan', 'Laurentiu', 'Gerolf']),
last: 'Smithy'
},
birthdate: function() { return new Date() }
})
Use that factory to create instances:
var human = humanFactory.create()
You can override the defaults if you like, using dot notation:
var chen = humanFactory.create({ 'name.first': 'Chen' })
You might want factories that are composed out of other factories:
var organizationFactory = unionized.factory({
name: 'Board Game Club',
members: unionized.array(humanFactory, 4)
})
organizationFactory.create()
You might want to pass arguments into your factory definitions:
var humanFactoryWithAge = humanFactory.factory (age) => {
birthDate: moment().subtract(age, 'years').toDate()
};
var legalDriver = humanFactoryWithAge.create({}, 16);
More features you may be interested in:
License
The MIT License (MIT)