Skip to content

Question: How to select an option in select input (mat-select) #184

@jk-kiran-palakurthi

Description

@jk-kiran-palakurthi

Target:
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions