unionized

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

npm install unionized
44 downloads in the last month

Unionized

A user-friendly factory system for easily building up complex objects. Entirely asynchronous. Recommended for use in testing, but you never know where else this could be useful!

NPM version Dependency status Build Status Coverage Status

Usage

Create complex objects really easily:


var unionized = require('unionized');
unionized.create({
  'pickup.pickupWindow.startAt': '2pm',
  'pickup.pickupWindow.endAt': '4pm',
  'pickup.name': 'San Francisco Ferry Building'
}, function(err, result) { console.log(result); });

// prints:
//   {
//      pickup: {
//        pickupWindow: {
//          startAt: '2pm',
//          endAt: '4pm',
//        },
//        name: 'San Francisco Ferry Building'
//     }
//   }

...or, better, define factories to create those objects for you:

pickupFactory = unionized.define(function(done) {
  this.set('pickup.pickupWindow.startAt', '2pm');
  this.set('pickup.pickupWindow.endAt', '4pm');
  this.set('pickup.name', 'San Francisco Ferry Building');
  done();
});
pickupFactory.create(function(err, result) { console.log(result); });

// prints:
//   {
//      pickup: {
//        pickupWindow: {
//          startAt: '2pm',
//          endAt: '4pm',
//        },
//        name: 'San Francisco Ferry Building'
//     }
//   }

now we can customize the objects that our factory returns us:

pickupFactory.create({
  'pickup.pickupWindow.startAt': '1am',
  'options.caveats': 'Customers are expected to bring their own shopping bags'
}, function(err, result) { console.log(result); });

// prints:
//   {
//      pickup: {
//        pickupWindow: {
//          startAt: '1am',
//          endAt: '4pm',
//        },
//        name: 'San Francisco Ferry Building'
//      },
//      options: {
//        caveats: 'Customers are expected to bring their own shopping bags'
//      }
//   }

License

The MIT License (MIT)

npm loves you