如何编写单元测试用例以使用 angular 重置单选按钮值

How to write unit test case to Reset the radio button values using angular

我正在尝试编写一个单元测试用例来清除单选按钮的选中值

点击删除图标 link 应该清除值

HTML 文件

 <mat-icon  class="remove-icon" (click)="resetradioValues('gender')">delete</mat-icon>

ts 文件

 resetradioValues(name: string){
    this.form.get(name).patchValue(null);
  }

我已经为上面的代码编写了一个单元测试用例,但它对我不起作用

it('should clear radio button values', () => {
    const param = Object.assign({},radio, { name: 'test' });
    console.log(param);
    component.resetradioValues(param.name);

    });

请让我知道任何人都可以解决这个问题

我们将通过实际单击图标并查看会发生什么来进行集成测试。

尝试:

it('should clear radio button values', () => {
      // arrangement
      const matIconElement = fixture.debugElement.query(By.css('mat-icon.remove-icon')).nativeElement;
      // click
      matIconElement.click();
      // assertions, you can assert how you like
      expect(component.form.get('test').value).toBe(null);
    });
// ========== Edit (Unit test) ==============
it('should clear radio button values', () => {
      // arrangement
      component.resetradioValues('test);
      // assertions, you can assert how you like
      expect(component.form.get('test').value).toBe(null);
    });