Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

factory-bro

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

factory-bro

[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url]

Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

factory-bro

NPM version build status Test coverage

A library for setting up JavaScript objects as test data.

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 factory-bro

Overview

/**
 * Initialize factory-bro.
 */

var factoryBro = require('factory-bro');
var factory = factoryBro();
var db = [];

/**
 * Add a fixture.
 */

factory.add('user', {
  name: 'Tobi',
  age: 7,
  species: 'Ferret'
});

/**
 * Define the persistance method.
 */

factory.persist(function(data) {
  db.push(data);
});

/**
 * Access our newly created 'user' fixture, edit it and then save it to the db.
 */

factory.user({name: 'Jane'});
console.log(db);
// => [{name: 'Jane', age: 7, species: 'ferret'}];

API

factory()

// Initialize a test factory.

var factoryBro = require('factory-bro');
var factory = factoryBro();

.add()

// Add a new fixture. Takes an argument of {String} name and {Object} data.

factory.add('user', {
  name: 'Tobi',
  age: 7,
  species: 'ferret'
});

.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.persist(function(data) {
  db.push(data);
});

.[fixtureName]()

// Access a fixture and edit its values. Takes an optional argument of 
// {Object} data. If applicable calls the function defined by .persist() after.

factory.user();
// persist -> {name: 'Tobi', age: 7, species: 'ferret'};

factory.user({
  name: 'Jane',
  age: 3
});
// persist -> {name: 'Jane', age: 3, species: 'ferret'}

License

MIT © Yoshua Wuyts

Keywords

factory_girl

FAQs

Package last updated on 30 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts