When I specify withArgs for a sinon spy or stub, I expect the callCount to only count calls with those arguments. This doesn't seem to be happening, though.
If I run the following:
var mySpy = sinon.spy();
mySpy.withArgs("foo");
mySpy("bar");
expect(mySpy.callCount).to.be(0);
I get "expected 1 to equal 0". Am I crazy, is this a bug, or is there another way to do this?
var stub = sinon. The original function can be restored by calling object. method. restore(); (or stub. restore(); ).
The function sinon. spy returns a Spy object, which can be called like a function, but also contains properties with information on any calls made to it. In the example above, the firstCall property has information about the first call, such as firstCall. args which is the list of arguments passed.
A test spy is a function that records arguments, return value, the value of this and exception thrown (if any) for all its calls.
You have to add withArgs to the assertion, too, like so:
var mySpy = sinon.spy();
mySpy.withArgs("foo");
mySpy("bar");
expect(mySpy.withArgs("foo").callCount).to.be(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With