Skip to content

Instantly share code, notes, and snippets.

Created February 17, 2017 20:53
What would you like to do?
Javascript Factories for Tests
const item = {
type: 'something',
age: 23,
person: {
name: 'Michael'
const createItem = params => ({...item, ...params})
// default item with some expected attr set that can be reused
const itemWithBall = createItem({type: 'ball'})
// factory function to create itemWithBall with other params for other attrs
const createBallItem = params => ({...itemWithBall, ...params})
console.log(createBallItem({age: 245}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment