可以使用类型断言或为类型添加属性来解决该问题。 例如,如果出现“Property 'propertyName' does not exist on type 'ComponentName'”错误,则可以在测试用例中使用类型断言来解决:
const component = fixture.componentInstance as any;
expect(component.propertyName).toBeTruthy();
或者,可以在组件的类型定义中添加该属性:
export class ComponentName {
propertyName: any;
...
}