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

161
Visualizações
RTL getByRole working weirdly. Why does It require extra characters to work properly?

I am trying to get an element with RTL ( React testing library ) getByRole method.

My observation:

It works when I add characters ( 12+ ).

Ex:

// Form

<Col xs={24} md={6}>
  <StyledLabel htmlFor="full-name-member">
    <LargeFont>Member Name_</LargeFont> // this line
  </StyledLabel>
  <TextBox
    name="fullName"
    placeholder="Full Name"
    required={false}
    rule="text"
    maxLength={100}
    id="full-name-member"
  />
</Col>;


screen.getByRole('textbox', { name: 'Member Name' });

Notice the extra _ underscore. It works when I add one more character than actually required.

I have counted the length for it. It's 12+ for working properly where If I remove an extra character, it doesn't work as it should.

Ex:

// Form

<Col xs={24} md={6}>
  <StyledLabel htmlFor="full-name-member">
    <LargeFont>Member Name</LargeFont> // this line
  </StyledLabel>
  <TextBox
    name="fullName"
    placeholder="Full Name"
    required={false}
    rule="text"
    maxLength={100}
    id="full-name-member"
  />
</Col>;


screen.getByRole('textbox', { name: 'Member Name' });

Explanation:

  • Styled is just a prefix for styled-component wrapped components.
  • Col & TextBox components belongs from ant-design.
  • LargeFont is a wrapper around div element with fixed css.

What could be the reason for this weird behaviour?

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