fix(testing): override metadata subclasses properly (#10767)

This fixes an issue where `TestBed.overrideComponent(MyComp, {})`
would remove some properties including `providers` from the component.

This was due to the override not properly dealing with getter fields
on subclasses.
This commit is contained in:
Julie Ralph
2016-08-12 17:39:33 -07:00
committed by vikerman
parent 9317056138
commit 87fe47737a
2 changed files with 46 additions and 7 deletions

View File

@ -118,13 +118,16 @@ function _valueProps(obj: any): string[] {
props.push(prop);
}
});
// getters
const proto = Object.getPrototypeOf(obj);
Object.keys(proto).forEach((protoProp) => {
var desc = Object.getOwnPropertyDescriptor(proto, protoProp);
if (!protoProp.startsWith('_') && desc && 'get' in desc) {
props.push(protoProp);
}
});
let proto = obj;
while (proto = Object.getPrototypeOf(proto)) {
Object.keys(proto).forEach((protoProp) => {
var desc = Object.getOwnPropertyDescriptor(proto, protoProp);
if (!protoProp.startsWith('_') && desc && 'get' in desc) {
props.push(protoProp);
}
});
}
return props;
}