I have created an Angular form component that uses <ng-select>
as a replacement for HTML <select>
elements. Now I want to unit test my component. To test the component logic I have methods that find HTML elements in the DOM and examine or modify their value. This works fine with native HTML elements. But <ng-select>
is difficult.
I can find the current value with something like this, but it feels like a very brittle solution.
document.querySelector("ng-select[formControlName=country] .ng-value .ng-value-label").innerText
And how do I change the selection? With a standard input component you can set the value, then fire an input event. There's an <input type="text" role="combobox">
inside <ng-select/>
, but changing its value doesn't seem to affect the FormControl value.
I'm not trying to test ng-select, but I do need to verify that my component reacts appropriately to selection changes. It will also be necessary to make selections in the UI when running automated integration tests.