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?
A 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 common syntax :)
// return mySpy.originalValue(param);
}
});
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