When it comes to Interfaces in Angular Karma Jasmine unit tests, I'm struggling with a specific error message. It's saying undefined for the first property of the interface and I can't get the component to run.
Cannot read property of 'primaryPropertyMailingAddressId' of undefined
Karma/Jasmine:
beforeEach(async(() => {
fixture = TestBed.createComponent(PropertySitusFinalizeComponent);
component = fixture.componentInstance;
component.jsonData = {}; // whether I remove or keep this line doesn't affect the error message
fixture.detectChanges();
}));
it('should create', () => {
expect(component).toBeTruthy();
});
Component:
export class PropertySitusFinalizeComponent implements OnInit {
@Input() jsonData: PropertySitusAddressContainer;
Interface:
export interface PropertySitusAddressContainer {
queueItemId?: number;
existingPropertySitusAddress?: PropertySitusAddress;
export class PropertySitusAddress {
primaryPropertyMailingAddressId?:number = null;
propertyId?: number = null;
propertySitusAddressId?: number = null;
addressFormatId?: number = null;
apn?: string = null;
Resource:
How to unit test model interfaces in typescript?