A basic tool providing an easy way to generate blocks of mock data for tests or as placeholders.
- Install NPM package
npm install --save-dev basic-factory
// OR YARN
yarn add --dev basic-factory
- Import Factory in
{appDir}/helpers/factories.js
// ES6
import BasicFactory from 'basic-factory'
- Initialize a new Factory
const factory = BasicFactory()
- Register your Factory generators
factory.register('User', () => {
// Would probably use Faker or something to generate these fields randomly.
return {
username: `user${Math.random() * 100}`,
email: `user${Math.random() * 100}`
}
})
- Export your Factory instance
export default factory
- Use factory in other files
import factory from '{appDir}/helpers/factories'
const oneUser = factory.create('User')
const arrayOfUsers = factory.createMany('User', 5)
-
yarn
/npm install
-
yarn test
/npm run test
See CONTRIBUTING.md