Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Slow getByRole leads to test timeouts

Aperta
#1,213 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, react

Direzione di ricerca

Inizia con la riproduzione collegata di Testing Playground e con l’entry point getByRole indicato, quindi esegui il profiling delle chiamate ripetute usando il render fornito in stile Ant Design. Confronta il tempo di esecuzione attuale con gli approssimativi 1,6 secondi per chiamata riportati; il lavoro è concluso quando la riproduzione non causa più timeout dei test senza modificare il comportamento previsto del test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

  • @testing-library/react version: 13.4.0
  • Testing Framework and version: "@nrwl/jest": "14.8.6"
  • DOM Environment: "@testing-library/jest-dom": "5.16.5"
Relevant code or config:
instance.getByRole('button', {
  name: 'tests.actions.add', hidden: true
  })
).toBeEnabled();
What you did:

I create rederresult with act<RenderResult> and try to find some elements on the screen.

This, with other buttons, is called like 6 times in this one test

What happened:

We migrate our code from andt4 to antd5. As we did this we noticed a lot of our test time out. They time out, because getByRole() takes a lot of time. Sure, Antd is part of the problem, but the rendered result is a rendered result and that should work. The Test, I send in the reproduction part, is just rendering, with some fetchMocks, so no UI changes after the setup.

Reproduction:

I tried to create a good reproduction, but with all our setup code, its complex. So I created a playground with the actual screen render.

https://testing-playground.com/gist/dcc46780eeacb3579d7b790f7fb4e577/c9e236ee04cfd77a19d8bb773e295010ed319ddb

Problem description:

getByRole() takes a lot of time in this jest test. I used the profiler to get a feeling, on how long.

Profiler

As you can see, for one getByRole() it takes around 1.6second. This adds up and leads to tests, that time out.

Suggested solution:

make getByRole fast 😅 I read a lot in the past weeks and someone said, this is slow (coudn't find the Issue again, sorry). I guess this could be improved.

cc @MLB00N

Lingua principale
JavaScript
Stelle
19.7k
Fork
1.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testing-library/react-testing-library

Tutte le issue di testing-library/react-testing-library

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.