Sinon Stub / Spy using WithArgs doesn't behave as expected

When I specify withArgs for a sinus spy or stub, I expect callCount to only count calls with these arguments. This does not seem to be happening.

If I run the following:

var mySpy = sinon.spy(); mySpy.withArgs("foo"); mySpy("bar"); expect(mySpy.callCount).to.be(0); 

I get "expected 1 equal to 0". Am I crazy, is this a mistake, or is there any other way to do this?

+4
source share
1 answer

You should also add withArgs to the statement:

 var mySpy = sinon.spy(); mySpy.withArgs("foo"); mySpy("bar"); expect(mySpy.withArgs("foo").callCount).to.be(0); 
+6
source

Source: https://habr.com/ru/post/1488122/


All Articles