Extend spyOnAllFunctions to include prototype and parent methods
This commit is contained in:
@@ -125,13 +125,25 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
||||
throw new Error('spyOnAllFunctions could not find an object to spy upon');
|
||||
}
|
||||
|
||||
for (var prop in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop] instanceof Function) {
|
||||
var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
||||
if ((descriptor.writable || descriptor.set) && descriptor.configurable) {
|
||||
this.spyOn(obj, prop);
|
||||
var pointer = obj,
|
||||
props = [],
|
||||
prop,
|
||||
descriptor;
|
||||
|
||||
while (pointer) {
|
||||
for (prop in pointer) {
|
||||
if (Object.prototype.hasOwnProperty.call(pointer, prop) && pointer[prop] instanceof Function) {
|
||||
descriptor = Object.getOwnPropertyDescriptor(pointer, prop);
|
||||
if ((descriptor.writable || descriptor.set) && descriptor.configurable) {
|
||||
props.push(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
pointer = Object.getPrototypeOf(pointer);
|
||||
}
|
||||
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
this.spyOn(obj, props[i]);
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
Reference in New Issue
Block a user