Add combined file for inherited spies
This commit is contained in:
@@ -2059,25 +2059,34 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
throw new Error(methodName + ' is not declared writable or has no setter');
|
throw new Error(methodName + ' is not declared writable or has no setter');
|
||||||
}
|
}
|
||||||
|
|
||||||
var spy = j$.createSpy(methodName, obj[methodName]);
|
var originalMethod = obj[methodName],
|
||||||
|
spiedMethod = j$.createSpy(methodName, originalMethod),
|
||||||
|
restoreStrategy;
|
||||||
|
|
||||||
|
if (Object.prototype.hasOwnProperty.call(obj, methodName)) {
|
||||||
|
restoreStrategy = function() {
|
||||||
|
obj[methodName] = originalMethod;
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
restoreStrategy = function() {
|
||||||
|
delete obj[methodName];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
currentSpies().push({
|
currentSpies().push({
|
||||||
spy: spy,
|
restoreObjectToOriginalState: restoreStrategy
|
||||||
baseObj: obj,
|
|
||||||
methodName: methodName,
|
|
||||||
originalValue: obj[methodName]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
obj[methodName] = spy;
|
obj[methodName] = spiedMethod;
|
||||||
|
|
||||||
return spy;
|
return spiedMethod;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.clearSpies = function() {
|
this.clearSpies = function() {
|
||||||
var spies = currentSpies();
|
var spies = currentSpies();
|
||||||
for (var i = spies.length - 1; i >= 0; i--) {
|
for (var i = spies.length - 1; i >= 0; i--) {
|
||||||
var spyEntry = spies[i];
|
var spyEntry = spies[i];
|
||||||
spyEntry.baseObj[spyEntry.methodName] = spyEntry.originalValue;
|
spyEntry.restoreObjectToOriginalState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user