admin管理员组文章数量:1291097
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'
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'
- Can explain what does not work, cause this is the right way to do it. – Andreas Köberle Commented Jul 12, 2013 at 14:40
- @AndreasKöberle when I do except(a.b.c).haveBeenCalled() I get Object [object Object] has no method 'tohaveBeenCalled' – lukas.pukenis Commented Jul 12, 2013 at 14:51
1 Answer
Reset to default 7I 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 :-)
本文标签: javascriptHow to spy on nested method in JasmineStack Overflow
版权声明:本文标题:javascript - How to spy on nested method in Jasmine? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741512119a2382666.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论