How to test option select using React Testing Library in javascript

Viewed 520

I'm trying to create a test simulating a user selecting a value from a drop down list but I keep getting the error that the error "Property 'selected' does not exist on type 'HTMLElement'."

fireEvent.change(screen.getByLabelText('Select Color'), { target: { value: 'blue' } })
expect(screen.getByTestId("no-color-selected").selected).toBe(false);
expect(screen.getByTestId("blue-selected").selected).toBe(true);

I'm not using a typescript file, so don't know why I'm getting a ts error

I also tried casting it to the proper type but I get the error that I can only do this in Typescript, not JS

    expect((screen.getByText('Color Selected: Blue') as HTMLOptionElement).selected).toBe(true);

Does anyone know how I can get around this or another way to test option select in javascript with react testing lib? Thanks!

0 Answers
Related