I am working on a component that mainly does its job on onNgInit() method:
stage = '';
onNgInit(){
const thus : any = this;
this.stage = "start';
this.uniService.dataExists().then(result=>{
// the data exists. get ProductTypes
that.stockService.productTypes().subscribe(proTypes=>{
vm.stage = "Setting status to products";
proTypes.map(product....);
});
});
}
now in my test, the value of stage remains "start" since the code is onNgInit, I believe. I was wondering if there is a way to watch for value change of variables or better yet, the very final value of a specific variable?
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import { TrackerComponent } from "./tracker.component";
describe("TrackerComponent", () => {
let component: TrackerComponent;
let fixture: ComponentFixture<TrackerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TrackerComponent]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TrackerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
//
it("should is created", () => {
expect(component).toBeTruthy();
expect(component.stage).toEqual('start');// want to track the changes
});
});