“All properties that are to be accessible in a template needs to be public. This is because Angular generates a separate TS class representing a template.” - pkozlowski-opensource
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MyComponent } from './my-component.component';
import { MyService } from '../services/my-service.service';
describe('ComicsListComponent', () => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyComponent ],
providers: [ MyService ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ComicsListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call myService serviceFunction', () => {
expect(component.loaderService.serviceFunction()).toHaveBeenCalled()
});
});
//src/my-component/my-component.ts
constructor(public myService: MyService) { }
Fixes:
Error: Property 'myService' is private and only accessible within class 'MyComponent'.
References: Github Issues