You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/contributing/frontend.md
+26Lines changed: 26 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -140,3 +140,29 @@ Choosing what to test is not always easy since there are a lot of flows and a lo
140
140
- Things that can block the user
141
141
- Reported bugs
142
142
- Regression issues
143
+
144
+
###Tests getting too slow
145
+
146
+
A few times you can notice tests can take a very long time to get done. Sometimes it is because the test itself is complex and runs a lot of stuff, and sometimes it is because of how we are querying things. In the next section, we are going to talk more about them.
147
+
148
+
####Using`ByRole` queries
149
+
150
+
One thing we figured out that was slowing down our tests was the use of`ByRole` queries because of how it calculates the role attribute for every element on the`screen`. You can read more about it on the links below:
Even with`ByRole` having performance issues we still want to use it but for that, we have to scope the "querying" area by using the`within` command. So instead of using`screen.getByRole("button")` directly we could do`within(form).getByRole("button")`.
156
+
157
+
❌ Not ideal. If the screen has a hundred or thousand elements it can be VERY slow.
158
+
159
+
```tsx
160
+
user.click(screen.getByRole("button"))
161
+
```
162
+
163
+
✅ Better. We can limit the number of elements we are querying.