How to spy on a nested method in Jasmine?

Consider this usual situation:

var a = { b: { c: function() {} } } 

I want to keep track of c and although this is easy:

 spyOn(ab, 'c'); 

However, he creates a spy, but he does not work. There are no errors or I see a spy there when debugging.

How can I track the nested method?

UPDATE

Exit: Object [object Object] has no method 'tohaveBeenCalledWith'

+8
javascript jasmine
source share
1 answer

I think a typo is a problem; spying on nested functions works well, as you drew.

Be careful with the case: the jasmine function toHaveBeenCalled() . Since you wrote toHaveBeenCalled() , the error message makes sense (because there is no such method). JavaScript is case sensitive :-)

+3
source share

All Articles