Fixtured
A library for easily creating and managing dynamic test data.
Installation
Latest release:
$ npm install fixtured
Master branch:
$ npm install http://github.com/sfurnival/fixtured/master
Usage
Creating Values
let Fixtured = ; let user = // Generate an int between 1 & 9999, and make sure // it's unique among all other 'user.id' values. id: FixturedGenerate // Generate a string of exactly length 15. fname: FixturedGenerate // Generate a string with a minimum length of 5 and // a maximum length of 15. lname: FixturedGenerate // Generate an int between 1 & 100 age: FixturedGenerate // Generate some fake lat/long values. latitude: FixturedGenerate longitude: FixturedGenerate // Use a Chance.js function email: FixturedGenerate;;
Defining Templates
let Fixtured = ; /** * Let's define a template for a 'User' type fixture. We'll * define the id as unique, so that each time we stamp out a * new instance, the id will be unique. */let Users = FixturedFixture; /** * Now we'll stamp out a couple users for us to work with * in our tests. */ let user_1 = Users;>> >> id: 5706>> fname: 'cfbb'>> lname: 'a10c'>> age: 35>> latitude: 54235359826125205>> longitude: 12592912316322327>> category: 'sports'>> rating: 420>> email: 'fc5912ddfa@test.com'>> let user_2 = Users;>> >> id: 192>> fname: 'bfc0123'>> lname: '7ffc0eea'>> age: 12>> latitude: -27685429360717535>> longitude: -1465287543553859>> category: 'sports'>> rating: 420>> email: 'd99efcc34a@test.com'>> /** * Now let's create a whole bunch of users to work with. */ let team = Users; // Array of 10 users /** * Now we'll create some more, but we'll key each one so * that we can access it later. */ let positions = 'Goaltender' 'Center' 'Left Wing' 'Right Wing' 'Left Defence' 'Right Defence'; let players = Users;>> >> "Goaltender": ... >> "Center": ... >> "Left Wing": ... >> "Right Wing": ... >> "Left Defence": ... >> "Right Defence": ... >> /** * Now we can also retrieve each user by their key. */ let goaltender = Users; /** * Don't care which user you work with for a test? */ let player = Users; // Some random keyed User fixture /** * ... or get a bunch of random Users */ let all_stars = Users; // Array of 5 random keyed Users