Warning: ⚠️ If you’re: 1


Warning: ⚠️ If you’re:
1. Using @TestingLib
2. Using getByRole
3. Testing on a page with many DOM elements…

Then getByRole may be slow.

Why? Because getByRole is "expensive", and @TestingLib uses JSDOM. JSDOM is written in JS, and thus, slower than the browser.

3 solutions:
1. Set hidden to true (avoids expensive visibility checks)
2. Use getByLabelText or getByText instead. They're faster.
3. Test in Playwright instead. (Playwright locators are inspired by @TestingLib). Since Playwright runs in a real browser, getByRole is fast.
@TestingLib More info here: https://testing-library.com/docs/queries/byrole/#performance
@TestingLib Correction: @TestingLib is often run with jsdom, but there are other options such as happydom or a real browser.

View original on X