#angular #typescript #radio-button #karma-jasmine
#угловой #машинописный текст #радиокнопка #карма-жасмин
Вопрос:
Цель
Я хочу проверить selection
, правильно ли задается свойство ngModule
, когда пользователь нажимает переключатель.
- У меня есть простой компонент с меткой и радиовходом
Шаблон
lt;label [for]="radioButton" class="k-label"gt; lt;ng-contentgt;lt;/ng-contentgt; lt;/labelgt; lt;input #radioButton type="radio" [name]="name" [value]="value" [(ngModel)]="selection" /gt;
Компонент
export class RadioOptionComponentlt;Tgt; { @Input() value: string; name: string; selection: T; constructor() { } }
Тест
it('should set ngModel to selection property', fakeAsync(() =gt; { const inputControl = fixture.debugElement.query(By.css('input')).nativeElement as HTMLInputElement; component.name = 'gender'; component.value = 'male'; fixture.detectChanges(); inputControl.click(); tick(); fixture.detectChanges(); expect(component.selection).toBe('male'); }));
Проблема
selection
Свойство не установлено и остается undefined