Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Test implementation details through the feature, not in isolation
Cover internal helper modules via the component/feature that uses them; reserve dedicated unit tests for complex internal logic.
Bad example
| 1 | // myfa.test.ts — tests the internal client directly |
| 2 | it('getFollowing returns person ids', async () => { /* ... */ }); |
| 3 | it('followPerson POSTs', async () => { /* ... */ }); |
| 4 | // FollowButton barely tested because internals are covered here |
Explanation (EN)
Testing internal helpers directly couples tests to implementation; refactors break tests even when user-visible behavior is unchanged.
Objašnjenje (HR)
Izravno testiranje internih helpera vezuje testove uz implementaciju; refaktori lome testove cak i kad se ponasanje vidljivo korisniku ne mijenja.
Good example
| 1 | // FollowButton.browser.test.tsx — tests behavior end to end |
| 2 | it('follows the person and shows confirmation', async () => { |
| 3 | page.render(<FollowButton personId={1} />); |
| 4 | await page.getByRole('button', { name: 'Follow' }).click(); |
| 5 | await expect.element(page.getByRole('status')).toBeVisible(); |
| 6 | }); |
Explanation (EN)
Exercising helpers through the feature keeps tests focused on observable behavior and survives internal refactors.
Objašnjenje (HR)
Provlacenjem helpera kroz znacajku testovi ostaju fokusirani na vidljivo ponasanje i prezivljavaju interne refaktore.
Exceptions / Tradeoffs (EN)
Keep a separate unit test when the internal logic has many edge cases that are hard or expensive to reach through the feature.
Iznimke / Tradeoffi (HR)
Zadrzi zaseban unit test kad interna logika ima mnogo rubnih slucajeva koje je tesko ili skupo doseci kroz znacajku.