Steve Fitzsimons
Steve Fitzsimons

Reputation: 3904

Angular 5 how to get Selected option text value from dropdown in component test

In an Angular component test, how can the sect value of a Select/dropdown be retrieved in a test?

I can get the value using expect(selectElement.nativeElement.value).toBe('1'); but cant figure out how to get the Text value to test

Upvotes: 2

Views: 2587

Answers (1)

Zammy
Zammy

Reputation: 573

You can get the .innerText from the selected option:

var select = selectElement.nativeElement;
var text = select.options[select.selectedIndex].innerText

Upvotes: 2

Related Questions