Why Jasmine Spy Doesn't Resolve The Function Object By Reference?
I have the following simple service app.factory('Shoes', function() { function a() {return 12;} function b() {return a();} return { a: a, b: b } })
Solution 1:
After you call spyOn(service, 'a')
, service.a
is no longer the a
you defined in the function -- it is a spy function. That spy function happens to call a
, but it is not a
; it has a different identity and is a different function.
However, setting the a
property of service
does not change the function a
you declared inside app.factory
. You've simply changed service
so that its a
property no longer refers to your original a
. By contrast, your b
function never changes its reference to the original a
. It gets a
straight from the local app.factory
scope in which a
and b
were originally declared. The fact that service
replaces its original a
with a spy does not affect b
's call to a()
, because it does not refer to service.a
.
Post a Comment for "Why Jasmine Spy Doesn't Resolve The Function Object By Reference?"