This is an old revision of the document!
Sinon JS
Spy
- Check if a method is called
const spy = sinon.spy(object, 'method') ... spy.restore() // remove spy expect(spy.callCount).to.be.eql(n) // check if the method is call n times
Stub
- Replace existing method with stub to avoid actually execute the method
function fake() { // a fake function to be called } const stub = sinon.stub(object, 'method').callFakes(fake) // you could also replace the fake with another real function ... stub.restore() // remove stub expect(stub.callCount).to.be.eql(n) // check if the method is call n times