bug(MatSelectHarness): getOptions() returns results from another harness
See original GitHub issueReproduction
Use StackBlitz to reproduce your issue: https://stackblitz.com/fork/components-issue
Steps to reproduce:
- Add two mat-selects with the same selector (e.g. id=“test”) but different ancestor selectors to a page. Both should be multiple-selects. Add 3 options in the first select and no options in the second.
- Write code that sets options of second select whenever selection within first select changes, so that the second select always contains only the options that are selected in the first select.
- Use test harness to click one option in first select, then use following code on the second test harness to check that only the single option is available:
await select.open();
const optionLabels = Promise.all((await select.getOptions()).map(option => option.getText()));
Expected Behavior
What behavior were you expecting to see?
- There should only be one option in the second select.
Actual Behavior
What behavior did you actually see?
- The options returned by the second select are the same as in the first - i.e. 3 options - even though when inspecting the component instance, I have verified that the options are correct (just one option).
Environment
- Angular: 9.1.7
- CDK/Material: 9.2.3
- Browser(s): Chrome v80
- Operating System (e.g. Windows, macOS, Ubuntu): macOS 10.15
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Unable to test Angular Material Select Component using ...
After some tinkering with the Select Harness API, I was able to solve this. I have updated the spec to get the host...
Read more >Create a component harness for your tests with Angular CDK
All component harness methods must return a promise. ... returned by this.getDropDown() , we have a MatSelectHarness in the select constant.
Read more >Testing Angular components with Material's Test Harnesses
In this article you will get a brief introduction to the topic of using Angular Material's component harnesses in your tests.
Read more >Testing with component harnesses
Using Angular Material's component harnesses in your tests ... All component harness APIs are asynchronous and return Promise objects.
Read more >How to use Angular Material harnesses to improve your ...
Here is the same scenario using an Angular Material Harness: const select = await loader.getHarness(MatSelectHarness); await select.open();
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, that will solve the problem. We use the ID to tie a select to its overlay panel. The panel uses a scheme that looks like
{{ id of the select }}-panel.The harnesses support any valid CSS selector so you could use an attribute or a class to distinguish between the selects.
I don’t think we want to add anything just to handle duplicate id’s. It sounds like you should open a bug against
ng-dynamic-forms