Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.8K
Visualizações
Jest The given element does not have a value setter

I'm currently writing Jest unit tests for two separate Material UI components that I am using: TextField and Menu.

In short, my component looks something like this:

MyComponent.js

<h3>Hello</h3>

<Textfield 
    name="myTextField"
    onChange={//onChangeMethod}
    value={//valueOfAState}
    inputProps={{ "data-testid": "textfield-input" }}
/>


<Menu
    open={true}
    data-testid="case-menu-select"
>
    <MenuItem>
        <ListItemText
            data-testid="list-item-select-option1"
            key="1"
        >
            First Item
        </ListItemText>
    </MenuItem>
    <MenuItem>
        <ListItemText
            data-testid="list-item-select-option2"
            key="2"
        >
            Second Item
        </ListItemText>
    </MenuItem>
</Menu>

Essentially, I'm trying to write a test that will select the second option from the Menu. I've written a test that looks something like this:

test("test menu select options", async () => {
    const { getByTestId } = Render(<MyComponent />)

    const text = getByTestId("textfield-input")
    fireEvent.change(text, { target: { value : "whatever text" } }) //works fine

    const menuSelect = getByTestId("case-menu-select")
    // select second option from the menu
    fireEvent.change(menuSelect, { target: { value: 2 } }) //fails
})

I'm getting an error at the line that fails:

The given element does not have a value setter

I've included the TextField example to showcase that it works. I've also tried to set an inputProps to the Menu component, but that doesn't exist.

How can I select an option from a Menu component?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda