testing-library / testing-library/react-testing-library

Slow getByRole leads to test timeouts

Open
#1,213 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
19.7k
Forks
1.2k
Avg merge
3d 16h
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Testing Playground reproduction and the named getByRole entry point, then profile the repeated calls using the provided Ant Design-style render. Compare the current execution time with the reported roughly 1.6 seconds per call; done means the reproduction no longer causes test timeouts without changing the test's intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
performance, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.