我正在学习实现 karma
& Jasmine
在 AngularJS 中,我将通过一些示例来更好地理解它。
我对 callThrough
有点困惑.
如果理解有误,请指正,与callFake()
略有相似之处以某种方式,我们实际上并未调用该函数。在 callFake()
我们还提供了一个具有返回类型但不在 callThrough
中的函数.
来自 Jasmine 文档:
By chaining the spy with and.callThrough, the spy will still track all calls to it but in addition it will delegate to the actual implementation.
请对此有所了解。
更新:
苦苦挣扎后,我意识到一篇文章值得分享。 Here is a Medium article to anyone who stumbles across this question
最佳答案
你的理解看起来不错:
spy :and.callThrough
By chaining the spy with and.callThrough, the spy will still track all calls to it but in addition it will delegate to the actual implementation.
spy :and.callFake
By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function.
If the function being spied on receives arguments that the fake needs, you can get those as well
加号:当您添加 callThrough 时。您不仅在跟踪 spy 的电话。您还可以调用该方法来测试它。这里的方法实际上是被调用的。在 callFake 时,您只能通过检查参数来测试它是否被正确调用。没有调用真正的方法。这是有道理的,因为它被称为
fake call
关于angularjs - 需要一些 Jasmine 中 "callThrough"和 "callFake()"的实际示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41414712/