Skip to content

Instantly share code, notes, and snippets.

@zackify
Last active March 11, 2018 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackify/d491b96a646203153b5b6b3d6daa7712 to your computer and use it in GitHub Desktop.
Save zackify/d491b96a646203153b5b6b3d6daa7712 to your computer and use it in GitHub Desktop.
mock.js
const getAppointments = Appointment => () => {
return Appointment.joins(:customer).where('customers.pays_a_lot = true').includes(:customer).order_by('customers.age DESC')
}
const dbmock = fakes => new Proxy({}, {
get: (target, name) => {
if(!fakes[name]) return this
return fakes[name]
}
)
test('gets appointments', () => {
let fakeAppointments = [{ id: 1, title: 'blah' }]
let appointments = getAppointments(dbmock({ order_by: () => fakeAppointments }))()
expect(appointments[0].title).toEqual('blah')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment