DataFactoryJs
Simple typescript factory for generating test data
Install
$ npm install --save-dev datafactoryjs
Usage
// Register models into the factory const factory = ; factory; // Generate a model const user = factory; // { id: '1', name: 'John Smith'} // Generate N models const users = factory; // [{ id: '1', name: 'John Smith' }, { id: '1', name: 'John Smith' }]
You can overwrite data with fixed attributes if you want to assert a value, this will match the keys of the original model by default or you can enable extending the model to allow new attributes
const users = factory; // [{ id:'1', name: 'Joe Doe' }] // Can enable extending the original model const users = factory; // [{ id:'1', name: 'Joe Doe', superPower: 'Super Strong' }]
The benefit of registering functions is being able to generate randomized data, I use Faker for this
const factory = ;const faker = ; factory