问题
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?
回答1:
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);
来源:https://stackoverflow.com/questions/17302269/sinon-stub-spy-using-withargs-not-behaving-as-expected