Use sinon.js to create a “spy object” with spy methods based on a real constructor/prototype
- 阅读更多 关于 Use sinon.js to create a “spy object” with spy methods based on a real constructor/prototype
I'm using sinon.js as a way to stub out dependencies in my Mocha tests. I prefer the 'spy' approach over a classic mock approach, as the introspection of the spy seems clearer and affords more flexibility than the somewhat backward-thinking with classic mock objects. That said, I wonder if I'm using it incorrectly when it comes to creating test spies for whole objects. Let's say I have a test dependency that has 4 methods on it and I want to stub each of those methods and make assertions on one or two of them. Currently I'm doing this: var spyObj = { aMethod: sinon.spy(), otherMethod: sinon