【发布时间】:2020-09-09 06:01:27
【问题描述】:
我有一个场景可以从基类中窥探受保护的属性。
export class BaseClass {
protected property1: string;
}
export class InheritedClass extends BaseClass, OnInit {
ngOnInit() {
this.populateProperties();
}
populateProperties() {
this.property1 = "test";
}
}
我正在尝试为此编写单元测试,但返回 property1 not found。可能是什么问题?
describe('populateProperties', () => {
it('should assign the properties values', () => {
// arrange
const spy = spyOnProperty((component as any), 'property1');
// act
component.populateProperties();
// assert
expect(spy).toBeDefined();
});
});
【问题讨论】:
标签: angular typescript jasmine karma-jasmine angular-unit-test