I have a number type initialized at the beginning of my component class like this: My component class:
import { .....
@Component({
....
})
export class JhiLoginModalComponent implements OnInit {
a: number;
ngOnInit() {
this.method();
}
method() {
a=3;
}
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;
....
});
//MY TEST
it ('Should print a value', async(() => {
fixture.detectChanges();
console.log('lalalalla' + comp.method.a); //It prints lalalaundefined
}));
It returns undefined when I print domElement and the error: Property a is undefined for type any
Do I make an error in injection?? How can I access the component elements otherwise?? If I use this number later it says that it is undefined.