I'm attempting to create a basic test function for a checkbox change event, but I'm encountering some issues running it. The error message states "Spec has no expectations," and the handler function is not included 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('should update myVariable value on checkbox change',fakeAsync(()=>{
myCheckBox = fixture.debugElement.query(By.css('#myCheckBox'));
spyOn(component, 'handleChange');
myCheckBox.triggerEventHandler('change',{target: myCheckBox.nativeElement});
tick();
fixture.detectChanges();
expect(component.myVariable).toBetrue;
}));
What's the best approach to write a Jasmine test case for validating this function and ensuring coverage of the if statement?