Skip to content

A simple model factory tool based on Laravel's Eloquent factories

Notifications You must be signed in to change notification settings

designmynight/factorista

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Factorista

A simple model factory tool bases on Laravel's Eloquent factories

Install

npm install designmynight/factorista --dev

Usage

This package is designed for easy use when no package builder (such as webpack) is being used.

We use this tool with Karma, in karam.conf.js, add the files

files : [
  'node_modules/faker/build/build/faker.js',
  'node_modules/designmynight/factorista/index.js'
]

Defining a factory

All functions available with Marak's Faker.js can be used

factoryDefine(User, (faker) => ({
  first_name: faker.name.firstName(),
  last_name: faker.name.lastName(),
}));

Calling a factory

// make a single user
const user = factory(User).make();

// make mulitple users
const users = factory(User, 5).make();

// make users with overrides
const users = factory(User, 5).make((faker) => ({
    first_name: 'Ralph',
    last_name: faker.lorem.word()
}));

About

A simple model factory tool based on Laravel's Eloquent factories

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published