You can associate the original method with a fake:
var obj = {
method: function(name) { return name + '!'; }
}
var methodFake = function(original, name) {
return 'faked ' + original(name);
}.bind(obj, obj.method)
spyOn(obj, 'method').andCallFake(methodFake);
obj.method('hello')
For what it's worth, I don't think it was a great practice, but lately it occurred to me that I was testing some d3 code. Hope this helps.
source
share