I am fairly new to unit testing. I am building an Angular component and my test suite is Jasmine/Karma.
My first test is complaining about two issues and I'm only trying to test an initialised variable value:
TypeError: Cannot set property 'http' of undefined
TypeError: Cannot read property 'isView' of undefined
The code is pretty simple so wondering why I'm getting these errors?
myComponent.ts
sView = false;
myComponent.spec.ts
describe('myComponent', () => {
let component: myComponent;
let fixture: ComponentFixture<myComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
schemas: [NO_ERRORS_SCHEMA],
declarations: [myComponent],
imports: [HttpClientTestingModule],
providers: [
{
provide: myService,
useFactory: myServiceMock
}
]
});
fixture = TestBed.createComponent(myComponent);
component = fixture.componentInstance;
});
it('isView defaults to: false', () => {
expect(component.isView).toEqual(false);
});
});
What is going on here?