Created
January 14, 2017 21:09
-
-
Save fakenickels/0bf865c4084bb2f41e9e53fb5e542ed8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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