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

112
Visualizações
How to select an input form that doesn't have a label with React testing library?

On this example, I'm trying to select the second input, change the value to some text and then fire the enter event. My main issue here is selecting the input since it doesn't have a label nor id

<ul>
  <form>
    <input value="" />
  </form>
  <form>
    <input value="" />
  </form>
</ul>

If anyone can help with I'd appreciate it.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I would suggest adding a name attribute to your input fields as it's something you want to do anyway, regardless of testing. This way the correct values are sent when submitting the form.

<ul>
  <form>
    <input value="" name="firstName" />
  </form>
  <form>
    <input value="" name="lastName" />
  </form>
</ul>

Test could be:

getByRole('textbox', {name: /lastName/i})

Side note: You have 2 form elements, if both inputs relate to the same form they should exist in the same form tag.

about 4 years ago · Juan Pablo Isaza Relatório

0

    const inputs = document.getElementsByTagName('input');
    console.log(inputs); // inputs[1] is second input 

Here is inputs

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
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