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

212
Visualizações
Why can't @testing-library/user-event interact with input elements?

i've made a small repo to demontstrate my issue: https://github.com/msawatzky75/user-event-input-test

i have a few different scenarios here:

  1. html button
  2. div with click handler
  3. checkbox with data-binding that is watched
  4. input that triggers every time its typed into

each of these triggers a fetch request that is handled by msw. i have also setup 2 different DOM environments to run these tests in: jsdom and happy-dom.

only the tests that interact with input elements (checkbox and the text input) fail and the results are consistant across DOM environments.

What is the issue here? is it a bug with @testing-library/user-event? if not, how could one go about fixing this?

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

0

The issue here is how the component is rendered. More specifically, how it is attached to the document body.

the original render is as follows:

const root = document.createElement("div");
const { queryByText, getByTestId, debug } = render(BaseApp, {
    container: root,
    attachTo: document.body,
});

the attachTo property seems to misbehave, but is resovled by doing this instead:

const root = document.createElement("div");
document.body.appendChild(root);
const { queryByText, getByTestId } = render(BaseApp, {
    container: root,
});

this brings the number of passing tests in this example from 4/8 to 7/8, with only the happy-dom checkbox test failing.

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