Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Slow getByRole leads to test timeouts

Offen
#1,213 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Muss geklärt werden
Aktivitätsstatus
Veraltet
Tech-Stack
javascript, react

Rechercherichtung

Beginne mit der verknüpften Testing Playground-Reproduktion und dem genannten getByRole-Einstiegspunkt und profiliere anschließend die wiederholten Aufrufe mit dem bereitgestellten Ant Design-artigen Rendern. Vergleiche die aktuelle Ausführungszeit mit den gemeldeten ungefähr 1,6 Sekunden pro Aufruf; abgeschlossen ist die Aufgabe, wenn die Reproduktion keine Test-Timeouts mehr verursacht, ohne das beabsichtigte Verhalten des Tests zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

  • @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

Vorherrschende Sprache
JavaScript
Sterne
19.7k
Forks
1.2k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus testing-library/react-testing-library

Alle Issues in testing-library/react-testing-library

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.