Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function spy(obj, methodName) {
- const spy = { count: 0 };
- const currentMethod = obj[methodName];
- if (!currentMethod) { return; }
- obj[methodName] = function (...args) {
- this.count++;
- return currentMethod.call(obj, ...args);
- }.bind(spy);
- return spy;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement