Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angular4单元测试使用选择更改事件更新模型_Angular_Unit Testing - Fatal编程技术网

angular4单元测试使用选择更改事件更新模型

angular4单元测试使用选择更改事件更新模型,angular,unit-testing,Angular,Unit Testing,似乎无法使用change事件对select控件的ngModel绑定进行测试: 组成部分: @Component({ selector: 'my-area', templateUrl: 'app/test.component.html' }) export class TestComponent { selectedFred; freds = [{name:"kruger"},{name:"Durst"}]; } 模板: <select [(ngModel)]="s

似乎无法使用
change
事件对
select
控件的
ngModel
绑定进行测试:

组成部分:

@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>
普朗克: 我做错了什么

使用
input
控件进行类似的单元测试就像一个符咒,请参见:

   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');
    }));