# unionized

> A factory framework for mock test objects in JavaScript. Will generate objects, models, and scenarios for tests.

Latest version **6.3.1** (published 2021-03-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install unionized
pnpm add unionized
yarn add unionized
bun add unionized
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.3.1 |
| Published | 2021-03-02 |
| First published | 2013-12-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 129.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Maintainers | goodeggs-admin, benbuckman, dannynelson, michaelkebbekus, dlau, demands, jhob |
| Keywords | factory, objects |

## Links

- npm: https://www.npmjs.com/package/unionized
- Repository: https://github.com/goodeggs/unionized
- Issues: https://github.com/goodeggs/unionized/issues
- npm.io page: https://npm.io/package/unionized

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [bluebird](https://npm.io/package/bluebird.md) ^3.0.5
- [fake-eggs](https://npm.io/package/fake-eggs.md) ^6.1.0
- [goodeggs-json-schema-validator](https://npm.io/package/goodeggs-json-schema-validator.md) ^4.5.2

## Recent versions

- 6.3.1 (latest) — 2021-03-02
- 6.1.0-0 (next) — 2019-12-11
- 6.3.0 — 2021-02-25
- 6.2.1 — 2020-12-16
- 6.2.0 — 2020-12-16
- 6.1.0 — 2019-12-11
- 6.0.0 — 2019-08-20
- 5.0.0 — 2018-07-10
- 4.12.2 — 2018-02-08
- 4.12.1 — 2018-02-08
- 4.12.0 — 2017-04-05
- 4.11.0 — 2017-01-31
- 4.10.1 — 2016-08-04
- 4.10.0 — 2016-08-03
- 4.9.0 — 2016-05-06
- … 39 more at https://npm.io/package/unionized/versions

## README

# Unionized

Unionized is a factory library for setting up JavaScript objects as test data. Compare to the [factory_girl](https://github.com/thoughtbot/factory_girl) Ruby gem by [thoughtbot](https://thoughtbot.com/open-source).

[![NPM
version](https://img.shields.io/npm/v/unionized.svg)](https://www.npmjs.com/package/unionized)
[![NPM
license](https://img.shields.io/npm/l/express.svg)](https://github.com/goodeggs/unionized/blob/master/LICENSE)
[![Dependency status](https://img.shields.io/david/goodeggs/unionized.svg)](https://david-dm.org/goodeggs/unionized)
[![Build Status](https://img.shields.io/travis/goodeggs/unionized.svg)](https://travis-ci.org/goodeggs/unionized)

# Links

- [Installation instructions](https://github.com/goodeggs/unionized/blob/master/docs/installation.md)
- [API Documentation](https://github.com/goodeggs/unionized/blob/master/docs/api.md)

# Examples

**Define** a factory:

```javascript
var humanFactory = unionized.factory({
  name: {
    first: unionized.enum(['Azrael', 'Bastiaan', 'Laurentiu', 'Gerolf']),
    last: 'Smithy'
  },
  birthdate: function() { return new Date() }
})
```

Use that factory to **create instances**:

```javascript
var human = humanFactory.create()
/*
 { name: { first: 'Gerolf', last: 'Smithy' }
   birthdate: Sun May 17 2015 16:52:25 GMT-0700 (PDT) }
*/
```

You can **override the defaults** if you like, using **dot notation**:

```javascript
var chen = humanFactory.create({ 'name.first': 'Chen' })
/*
 { name: { first: 'Chen', last: 'Smithy' }
   birthdate: Sun May 17 2015 16:58:19 GMT-0700 (PDT) }
*/
```

You might want factories that are **composed out of other factories**:

```javascript
var organizationFactory = unionized.factory({
  name: 'Board Game Club',
  members: unionized.array(humanFactory, 4)
})
organizationFactory.create()
/*
 { name: 'Board Game Club',
   members: [
     { name: { first: 'Bastiaan', last: 'Smithy' },
       birthdate: Sun May 17 2015 17:09:52 GMT-0700 (PDT) },
     { name: { first: 'Azrael', last: 'Smithy' },
       birthdate: Sun May 17 2015 17:09:52 GMT-0700 (PDT) }
     { name: { first: 'Gerolf', last: 'Smithy' },
       birthdate: Sun May 17 2015 17:09:52 GMT-0700 (PDT) }
     { name: { first: 'Bastiaan', last: 'Smithy' },
       birthdate: Sun May 17 2015 17:09:52 GMT-0700 (PDT) }
   ] }
*/
```

You might want to **pass arguments into your factory definitions**:

```javascript
var humanFactoryWithAge = humanFactory.factory (age) => {
  birthDate: moment().subtract(age, 'years').toDate()
};

var legalDriver = humanFactoryWithAge.create({}, 16);
/*
   { name: { first: 'Azrael', last: 'Smithy' }
     birthdate: Sun May 17 2000 15:00:02 GMT-0700 (PDT) }
*/
```

More features you may be interested in:

- [Factory inheritance](https://github.com/goodeggs/unionized/blob/master/docs/api.md#example)
- [Auto-generating factories from schemas (currently supported: JSON-schema and mongoose)](https://github.com/goodeggs/unionized/blob/master/docs/api.md#factorymongoosefactory)
- [Asynchronous factories](https://github.com/goodeggs/unionized/blob/master/docs/api.md#example-2)

# License

[The MIT License (MIT)](https://github.com/goodeggs/unionized/blob/master/LICENSE)

---
_Source: https://npm.io/package/unionized · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
