MatSelect ntegration testing

Viewed 10

I want to test my component that uses mat-select. I have to trigger openedChange event with value == true so I can proceed to get options for select Tried like this

    const selectHarness = await loader.getHarness<MatSelectHarness>(MatSelectHarness);
    await selectHarness.open()

or this way

const matSelect = debugElement.query(By.css('.mat-select-trigger')).nativeElement;
matSelect.click();

or this way

fixture.debugElement.query(By.css('mat-form-field')).triggerEventHandler('selectionChange', { value: true });


@ViewChild(MatSelect, { static: false }) select!: MatSelect;

...

this.select.openedChange
  .subscribe((value: boolean) => {
    if (value) {
      this.subscribeToSearchInput();
      this.focusInput();
      this.registerPanelScrollEvent()
      this.subscribeToLoadOptions();
    } else
      this.inputSubscribtion?.unsubscribe();
  })
0 Answers
Related