node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »


Basic Factory

Build Status

A basic tool providing an easy way to generate blocks of mock data for tests or as placeholders.

Basic Usage

  1. Install NPM package
  npm install --save-dev basic-factory
  // OR YARN
  yarn add --dev basic-factory
  1. Import Factory in {appDir}/helpers/factories.js
// ES6
import BasicFactory from 'basic-factory'
const BasicFactory = require('basic-factory').default
  1. Initialize a new Factory
const MyFactory = new BasicFactory()
  1. Register your Factory generators
MyFactory.register('User', () => {
  // Would probably use Faker or something to generate these fields randomly.
  return {
    username: `user${Math.random() * 100}`,
    email: `user${Math.random() * 100}`
  1. Export your Factory instance
export default MyFactory
  1. 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