At the start of my component class, I initialize a number type like so:
import { .....
@Component({
....
})
export class JhiLoginModalComponent implements OnInit {
a: number;
ngOnInit() {
this.method();
}
method() {
a=3;
}
In my testing class:
import {...
describe('LoginComponent', () => {
let comp: ComponentClass;
let fixture: ComponentFixture<ComponentClass>;
beforeEach(async(() => {
TestBed.configureTestingModule({
............
}));
beforeEach(() => {
fixture = TestBed.createComponent(ComponnetClass);
comp = fixture.componentInstance;
....
});
it ('Should display a value', async(() => {
fixture.detectChanges();
console.log('lalalalla' + comp.method.a); //It prints lalalaundefined
}));
When I print domElement, it shows undefined and displays the error message: Property a is undefined for type any
Did I make an injection mistake?? How can I access the component elements differently? If I try to use this number later on, it signifies that it is undefined.