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