Skip to content

Instantly share code, notes, and snippets.

@fatso83
Last active February 28, 2019 09:10
Show Gist options
  • Save fatso83/ba6151072c3db5748e3bf7c63bb3b84d to your computer and use it in GitHub Desktop.
Save fatso83/ba6151072c3db5748e3bf7c63bb3b84d to your computer and use it in GitHub Desktop.
const sinon = require('sinon');
const stub = sinon.stub();
const spy = sinon.spy(function(){});
function test(spy){
spy(1,2,3,4);
spy(1,2);
spy(1,2);
spy(1);
console.log(spy.calledWith(1,2,3,4));
console.log(spy.withArgs(1,2,3,4).calledOnce);
console.log(spy.withArgs(1,2,3,4).callCount === 1);
console.log(spy.calledWith(1,2));
console.log(spy.withArgs(1,2).calledOnce === false);
console.log(spy.withArgs(1,2).callCount === 3);
// missing
// console.log(spy.calledWithExactly(1,2));
// console.log(spy.calledWithExactly(1,2).calledOnce);
}
test(spy);
test(stub);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment