Consider this usual situation:
var a = {
b: {
c: function() {}
}
}
I want to spy on c and though it's easy with:
spyOn(a.b, 'c');
However it creates a spy but it doesn't work. No errors or so are shown and I can see there's a spy when debugging.
How can I spy on a nested method?
UPDATE
Output is: Object [object Object] has no method 'tohaveBeenCalledWith'
I guess typo is the problem; spying on nested functions works well as you outlined.
Be carefull with the casing: Jasmine function is toHaveBeenCalled()
. Since you wrote tohaveBeenCalled()
the error message makes sense (because there is no such method). JavaScript is case-sensitive :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With