Sinon Stub/Spy Using WithArgs Not Behaving As Expected

笑着哭i 提交于 2019-12-10 17:08:59

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!