Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created January 14, 2017 21:09
Show Gist options
  • Save fakenickels/0bf865c4084bb2f41e9e53fb5e542ed8 to your computer and use it in GitHub Desktop.
Save fakenickels/0bf865c4084bb2f41e9e53fb5e542ed8 to your computer and use it in GitHub Desktop.
import { Mongo } from 'meteor/mongo'
import { Meteor } from 'meteor/meteor'
function addConsoleSpyOn({object, methods, spyFn}){
const oldMethods = methods.reduce((acc,name) => ({...acc, [name]: object[name]}), {})
methods.forEach(method => {
object[method] = function(...args){
spyFn({instance: this, args, method})
return oldMethods[method].call(this, ...args)
}
})
}
addConsoleSpyOn({
object: Mongo.Collection.prototype,
methods: ['find', 'findOne', 'update'],
spyFn({ instance, args, method }){
console.log(`\n\n${instance._name}.${method} called with ${args.length} args`)
args.forEach(arg => console.log(arg))
console.log('\n\n')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment