我一直在阅读单元测试的官方Angular2文档(https://angular.io/docs/ts/latest/guide/testing.html),但我很难设置组件的输入字段值,以便其反映在组件属性中(通过ngModel绑定).屏幕在浏览器中运行良好,但在单元测试中,我似乎无法设置字段值.
我使用下面的代码.当其他测试正常运行时,"fixture"已正确初始化."comp"是我的组件的实例,输入字段通过ngModel绑定到"user.username".
it('should update model...', async(() => {
let field: HTMLInputElement = fixture.debugElement.query(By.css('#user')).nativeElement;
field.value = 'someValue'
field.dispatchEvent(new Event('input'));
fixture.detectChanges();
expect(field.textContent).toBe('someValue');
expect(comp.user.username).toBe('someValue');
}));
我的版本"天使2:"@angular/core": "2.0.0"
"