admin管理员组文章数量:1316616
I have a method which returns function references.
function methodetobeMoked(param){
case1:return func1;
case 2: return func2;
.
.
case n: return funcN;
}
I need to spy this method and return a fake function reference for a particular input param p
Is there any conditional callThrough in jasmine tests My scenario is
SpyOn(some object,'someMethode').and.{if param=p callFake(fakeMethode) else callThrough()}
I tried callFake Is there any way to pass control to original method from fake method?
I have a method which returns function references.
function methodetobeMoked(param){
case1:return func1;
case 2: return func2;
.
.
case n: return funcN;
}
I need to spy this method and return a fake function reference for a particular input param p
Is there any conditional callThrough in jasmine tests My scenario is
Share Improve this question asked Jun 21, 2016 at 12:26 Able JohnsonAble Johnson 5717 silver badges31 bronze badges
SpyOn(some object,'someMethode').and.{if param=p callFake(fakeMethode) else callThrough()}
I tried callFake Is there any way to pass control to original method from fake method?
1 Answer
Reset to default 10A Jasmine spy retains the original function in a property named originalValue
, so you can do something like:
var mySpy = {};
mySpy = t.spyOn(obj, 'methodToBeMocked').and.callFake(function (param) {
if (param === 'fake case') {
// return fake result
} else {
// do this if using Jasmine
return (mySpy.and.callThrough())(param);
// do this if using Ext + Siesta and duped by mon syntax :)
// return mySpy.originalValue(param);
}
});
本文标签: javascriptJasmine conditional callThrough and callFakeStack Overflow
版权声明:本文标题:javascript - Jasmine conditional callThrough and callFake - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741958967a2407156.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论