Now spies preserve original function arity

This commit is contained in:
Andrzej Kopeć
2016-02-25 21:43:18 +01:00
parent 4e4cd30965
commit 90dea9ab38
4 changed files with 78 additions and 32 deletions

View File

@@ -62,38 +62,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
};
j$.createSpy = function(name, originalFn) {
var spyStrategy = new j$.SpyStrategy({
name: name,
fn: originalFn,
getSpy: function() { return spy; }
}),
callTracker = new j$.CallTracker(),
spy = function() {
var callData = {
object: this,
args: Array.prototype.slice.apply(arguments)
};
callTracker.track(callData);
var returnValue = spyStrategy.exec.apply(this, arguments);
callData.returnValue = returnValue;
return returnValue;
};
for (var prop in originalFn) {
if (prop === 'and' || prop === 'calls') {
throw new Error('Jasmine spies would overwrite the \'and\' and \'calls\' properties on the object being spied upon');
}
spy[prop] = originalFn[prop];
}
spy.and = spyStrategy;
spy.calls = callTracker;
return spy;
return new j$.Spy(name, originalFn);
};
j$.isSpy = function(putativeSpy) {