I have a component that resets certain variables to null on ngOnInit.
(我有一个组件,可以将ngOnInit上的某些变量重置为null。)
(Note that if I am move the variable resetting to the constructor of the component, it works great but since I didn't write the component in the first place, I am curious to see if changeDetection can be turned off on a test by test case from the spec file.) That is affecting one specific test which needs a variable to pass but the variable is reset to null. ((请注意,如果我将变量重置移动到组件的构造函数中,则效果很好,但是由于我没有首先编写组件,因此我很想知道是否可以在每次测试中关闭changeDetection这会影响一个特定的测试,该测试需要通过变量,但该变量会重置为null。)
What I am hoping to get is in my test case to turn of fixture.detectChanges() but still set variable values from it that can be picked or that is not possible?
(我希望得到的是在测试用例中转到Fixture.detectChanges(),但仍然从中设置可以选择或不可能的变量值?)
component:
(零件:)
export class TravelRequestComponent implements OnInit {
fieldType : number = null;
ngOnInit(){
this.fieldType = null;
}
setFieldType(fieldType){
this.fieldType = fieldType
}
processForm(){
console.log(this.fieldType); //null all the time
if(this.fieldType){
//process form
}
else{
this.toastr.error("","Select Field Type");
}
}
}
setFieldType is called from a dropdown element.
(setFieldType是从下拉元素中调用的。)
beforeEach(() => {
fixture = TestBed.createComponent(TravelRequestComponent);
component = fixture.componentInstance;
//implementation
fixture.detectChanges();
});
it("should return the same user", ()=>{
component.countiesList = MockData.Counties;
component.fieldType = 1;
fixture.detectChanges();
component.processForm();
});
ask by Wede Asmera Tseada translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…