Sinon: spy.call 接受呼叫计数以验证呼叫计数

创建于 2014-01-22  ·  3评论  ·  资料来源: sinonjs/sinon

有一个功能会很方便

spy.called(6).times // returns true if spy have been called 6 times

比我可以使用sinon-chai

spy.should.have.been.called(6).times

最有用的评论

使用spy.callCount来查看调用次数。

所有3条评论

当然spy.called没有函数调用应该像今天一样工作

使用spy.callCount来查看调用次数。

@cjohansen我使用spy.calledTwice而不是spy.callCount === 2是有原因的,因为它更具可读性。 (它也可以和 sinon-chai 一起玩)。 虽然我可能应该在sinon-chai repo 上提交问题。

此页面是否有帮助?
0 / 5 - 0 等级