I am new to Jasmine tests and I am trying to write unit test for change event,which requires event as mock value in the method argument and I am unable to achieve it. this is what I have tried
it('sample test', () => { const compiled = fixture1.debugElement; const event = { preventDefault: jasmine.createSpy(), srcElement: jasmine.createSpy() }; spyOn(component1, 'onChange'); const select = compiled.query(By.css('#elect-menu')).nativeElement; select.value = select.options[1].value; select.dispatchEvent(new Event('change')); fixture1.detectChanges(); expect(component1.onChange).toHaveBeenCalled();` my html code looks like this
<select id="select-menu" (change)="onChange($event)" (dblclick)="onChange($event)"> <option value="default">some value</option> <option *ngFor="let line of lines" [value]="line.id" >{{line.name}}</option> </select> my component method which will be called on change onChange($event) {
const selected = parseInt($event.target.value); switch (selected) { case 1: { //some logic break; } } I want to write a test case to test positive and negative flows in case 1.