factory-bro
Defining fixtures is repetitive and prone to errors. Factory-bro helps you by allowing fixtures to be defined in a central hub. This allows you to spend more time coding, and less time updating tests.
Installation
$ npm i --save-dev factory-bro
Overview
/** * Initialize factory-bro. */ var factoryBro = ;var factory = ;var db = ; /** * Add a fixture. */ factory; /** * Define the persistance method. */ factory; /** * Access our newly created 'user' fixture, edit it and then save it to the db. */ factory;console;// => [{name: 'Jane', age: 7, species: 'ferret'}];
API
factory()
// Initialize a test factory. var factoryBro = ;var factory = ;
.add()
// Add a new fixture. Takes an argument of {String} name and {Object} data. factory;
.persist()
// Define the function to be called when an object gets persisted. Takes a // {Function} func as an argument. The func is provided with an argument of// {Object} data when called. var db = ; factory;
.[fixtureName]()
// Access a fixture and edit its values. Takes an optional argument of // {Object} data. If applicable calls the function defined by .persist() after. var user = factory; console;// => {name: 'Tobi', age: 7, species: 'ferret'}console;// => [{name: 'Tobi', age: 7, species: 'ferret'}]; user = factory; console;// => {name: 'Jane', age: 3, species: 'ferret'}console;// => [// {name: 'Tobi', age: 7, species: 'ferret'},// {name: 'Jane', age: 3, species: 'ferret'}// ]