我正在研究一个主要在 onNgInit() 方法上完成其工作的组件:
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....);
});
});
}
现在在我的测试中,我相信,由于代码是 onNgInit,stage 的值仍然是“start”。我想知道是否有办法观察变量的值变化,或者更好的是,特定变量的最终值?
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
});
});