Assembly Line
Simple, reusable javascript object factories – great for writing tests.
Usage
Basic usage:
var AssemblyLine = ; // define a factoryvar user = AssemblyLine // call the factory to create an instancevar jsmith = ;
AssemblyLine.factory()
The Factory method accepts two arguments: the constructor class you want to use for your objects and a set of attributes to user when creating instances.
Example:
// define a custom constructorvar { thisparams = params;} // define factoriesvar Factories = jason: AssemblyLine var jason = Factories;console;// => { params: { name: 'Jason', hometown: 'Jackson, Mississippi' }}
AssemblyLine.sample()
The Sample method accepts one argument: an array or options to choose from. When a factory's attribute is set using the sample method, new instances will be created and assigned a random value from the options array.
Example:
var user = AssemblyLine var user1 = ;// user1.name will be one of james, jason, jenny, or janice
AssemblyLine.incr()
The Increment method accepts one argument: a string that should be used as the base value to increment on. When a factory's attribute is set using the increment method, new instances will be created by replacing #{i}
with an incrementing integer. This is useful for ensuring unique email addresses, etc when testing.
Example:
var user = AssemblyLine var user1 = ;// user1.email => person1@example.com var user2 = ;// user2.email => person2@example.com