I am learning to implement karma & Jasmine in AngularJS and I am going through some of its examples to understand it better.

I am little bit confused about callThrough.

Please correct me if I am misunderstanding it, it's slightly similar to callFake() in a way that we are not actually calling the function. In callFake() we also provide a function with the return type but not in callThrough.

From Jasmine doc:

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.

Please shed some light on this.

Update:

After struggling through it, i realized that an article is worth sharing. Here is a Medium article to anyone who stumbles across this question

0

1 Answer

Your understanding looks good:

Spies: 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.

Spies: 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

Plus: when you add callThrough. you are not only tracking the calls by the spy. You also call the method to test it. The method here is actually called. While on callFake you only test if its gets called correctly by checking the arguments. The real method is not called. That makes sence since its called fake call

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.