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:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user