Skip to content

Instantly share code, notes, and snippets.

@amite
Created April 20, 2017 15:14
Show Gist options
  • Save amite/ff43a9981f809a1a847efdee47691819 to your computer and use it in GitHub Desktop.
Save amite/ff43a9981f809a1a847efdee47691819 to your computer and use it in GitHub Desktop.
Faker Factories
let faker = require('faker')
const getRandom = (arr) => arr[Math.floor(Math.random()*arr.length)]
const createCombos = (foodNames, foodTypes) => foodNames.map( (item, index) => `${getRandom(foodTypes)} ${item}`)
const foodNames = ['Samosa', 'Sandwich', 'Roll', 'Pattice']
const foodTypes = ['Non Veg', 'Veg', 'Jain']
function Combo() {
return {
contents: createCombos(foodNames, foodTypes),
price: faker.commerce.price(),
}
}
const make = (num = 5) => fn => Array.from({length: num}, fn);
let fakeComboFactory = make(30)
// console.log(fakeUsers)
let combos = fakeComboFactory(Combo)
// console.clear()
console.log(combos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment