2
のラジオボタンをチェックしてください:は、私は、このHTMLと角度の成分を持つ角度ユニットテスト
<div class="row">
<label for="tipo" class="column">Tipo: </label>
<div *ngFor="let tipo of tipos" class="column">
<input type="radio" name="tipo" [value]="tipo.id"
[(ngModel)]="movimiento.tipo" (ngModelChange)="alCambiarTipo()">
<span class="{{tipo.texto | lowercase}}">{{ tipo.texto }}</span>
</div>
</div>
それは2つのラジオボタンがあり、変化に、それは私のコンポーネントで機能をトリガします。私のテストでは、私の関数が呼び出されたことをテストするために2番目のラジオボタンをチェックしたいと思います。私はこのコードを試してみたが、それは働いていない:
it('should call alCambiarTipo on radio button change',() => {
spyOn(component, 'alCambiarTipo').and.callThrough();
let options: DebugElement[] = fixture.debugElement.queryAll(By.css('input[type="radio"]'));
let secondOption: HTMLInputElement = options[1].nativeElement;
secondOption.checked = true;
expect(component.alCambiarTipo).toHaveBeenCalled();
});
私も入力に.click()
を使用してみました、それはまた、働いていません。私の機能を引き起こすために私は何ができますか?ありがとう。
PS:component.movimiento.tipo = 1;
を追加してfixture.detectChanges()
を追加してモデルを変更しようとしましたが、動作しません。
チェック設定する必要はありません。これを解決しましたか? –