I am trying to write simple test function for check box change, but I am unabled to run it. The error is Spec has no expectations. and the handler function is not covered in code coverage,.
template:
<input type="checkbox" (change)="handleChange($event)">
handler function:
handleChange(event:any){
if(event.target.checked){
this.myVariable= true;
}else{
this.myVariable = false;
}
}
Test case:
it('checkbox change should set the myVariable value',fakeAsync(()=>{
myCheckBox = fixture.debugElement.query(By.css('#myCheckBox'));
spyOn(component, 'handleChange');
myCheckBox.triggerEventHandler('change',{target: myCheckBox.nativeElement});
tick();
fixture.detectChanges();
expect(component.myVariable).toBetrue;
}));
How should I write Jasmine test case to check this function and also cover if statement.