Skip to content

Instantly share code, notes, and snippets.

@mikeLspohn
Created February 17, 2017 20:53
Show Gist options
  • Save mikeLspohn/b9a9b08e6403f2f169f71b9470212d4e to your computer and use it in GitHub Desktop.
Save mikeLspohn/b9a9b08e6403f2f169f71b9470212d4e to your computer and use it in GitHub Desktop.
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