Question: How to select an option in select input (mat-select)
See original GitHub issueTarget: I am writing a module where I need to hide input elements based on some conditions. I need to select an option of material select input.
Problem:
Unable to test it, the test assertion throws error.
TestingLibraryElementError: Value "Partnership" not found in options
Reproduction:
- I am loading mat options using *ngFor (below are my options)
[
{
value: 'Public Limited Company',
label: 'Public Limited Company',
},
{
value: 'Private Limited Company',
label: 'Private Limited Company',
},
{
value: 'Partnership',
label: 'Partnership',
},
{
value: 'Limited Liability Partnership',
label: 'Limited Liability Partnership',
}
]
- Below is my assertion code.
const firmType = screen.queryByLabelText(/Firm Type/i);
const isGstPresent = screen.queryByLabelText(/Is Gst Available/i);
const gstNumber = screen.queryByLabelText(/GST Number/i);
userEvent.selectOptions(firmType, 'Partnership');
await waitFor(() => {
expect(isGstPresent).toBeInTheDocument();
expect(taxPayerType).not.toBeInTheDocument();
});
Any help is appreciated.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Why can't select a mat-option of mat-select? - Stack Overflow
Method 1. Replace [value] with value in your <mat-option [value]="nam">Nam</mat-option> when your value is not dynamic. Method 2.
Read more >Select | Angular Material
<mat-select> is a form control for selecting a value from a set of options, similar to the native <select> element. You can read...
Read more ><mat-select> in Angular Material - GeeksforGeeks
<mat-select> tag is used to display the options in a dropdown. ... Then use <mat-select> tag to group all the items inside this...
Read more >Angular Material Select - Javatpoint
Angular Material Select. <mat-select> is a form control used for selecting a value from a set of options. It is same as the...
Read more >ngx-mat-select-search - npm
Angular component providing an input field for searching / filtering MatSelect options of the Angular Material library.
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
This is the
userEvent
correct use format-select
The link above is dead (possible file moving?) The new link with the example