似乎无法使用ngModel
控件change
事件测试select
绑定:
成分:
@Component({
selector: 'my-area',
templateUrl: 'app/test.component.html'
})
export class TestComponent {
selectedFred;
freds = [{name:"kruger"},{name:"Durst"}];
}
模板:
<select [(ngModel)]="selectedFred">
<option *ngFor="let f of freds" [ngValue]="f">{{f.name}}</option>
</select>
试验:
it('should allow us to set a bound select field', fakeAsync(() => {
let input = fixture.debugElement.query(By.css('select')).nativeElement;
console.error(input);
input.value = component.freds[1];
input.selectedValue = component.freds[1];
input.dispatchEvent(new Event('change'));
tick();
expect(component.selectedFred.name).toEqual('Durst');
}));
plunkr:https://plnkr.co/edit/ZXJ6bsjfu78d4m928U8S?p=preview 我究竟做错了什么?
使用input
控件的类似单元测试就像魅力一样,请参阅:https://plnkr.co/edit/0ELwf5W26XoBlKa5Y5xA?p=preview