Skip to content

Commit 550e9c4

Browse files
authored
docs: update unit testing FAQ with clarified answers and improved wording (#1821)
1 parent 9c37bf4 commit 550e9c4

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

react/modules/tasks/tests.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,54 @@ You must use **Jest** or **Vitest** as the test runner and **React Testing Libra
159159
4. Tests must be deterministic (no flaky tests)
160160
5. All external dependencies must be properly mocked
161161

162-
## Points Distribution
162+
## Points
163163

164-
### Student can get 100 points
164+
A student can achieve a maximum of 100 points.
165+
166+
## 📚 FAQ (Frequently Asked Questions)
167+
168+
### ❓ Am I allowed to modify existing components to make testing easier?
169+
170+
Yes — if necessary, you are allowed to modify the component code to improve testability. Just make sure you don’t change the logic or convert class components to functional ones.
171+
172+
### ❓ Can I add data-testid attributes?
173+
174+
Yes. You may add data-testid attributes if necessary, but prefer semantic queries such as getByRole, getByLabelText, or getByText, following Testing Library’s query priority.
175+
176+
### ❓ Can I use real API calls in tests?
177+
178+
No. You must test your code, not the backend. All API calls should be mocked using `jest.mock`, `vi.mock`, or tools like Mock Service Worker (MSW). Tests should not rely on external services.
179+
180+
### ❓ If one file has low coverage but overall project coverage is fine, will I lose points?
181+
182+
No. The rule applies to the total (global) coverage only.
183+
184+
### ❓ How do I set up coverage threshold?
185+
186+
In your test config (e.g., jest.config.js):
187+
188+
```
189+
coverageThreshold: {
190+
global: {
191+
statements: 80,
192+
branches: 50,
193+
functions: 50,
194+
lines: 50,
195+
},
196+
},
197+
```
198+
199+
### ❓ Should I test main.tsx or App.tsx?
200+
201+
You don’t need to test main.tsx directly. Focus on components like App.tsx and everything rendered within it.
202+
203+
### ❓ Is deployment required for this task?
204+
205+
No, deployment is not mandatory for the unit testing task.
206+
That said, deploying your app (e.g., to GitHub Pages, Vercel, or Netlify) is highly recommended — it makes the review process easier and demonstrates good development practice.
207+
If you'd like to deploy, feel free to do so, but it won’t affect your score.
208+
209+
### Cross-check (score can be less if some parts of the functionality don't work)
165210

166211
- **Test Runner Setup** (Jest/Vitest configured with RTL, coverage reporting works) - **15 points**
167212
- **Search Component Tests** (localStorage, user input, search functionality) - **20 points**

0 commit comments

Comments
 (0)