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 shared variant behavior in one parameterized suite, not per-variant files
Cover behavior common to multiple variants via a single shared/parameterized test; don't test private implementation-detail subcomponents in isolation.
Bad example
| 1 | // mobileSquareIcons.browser.test.tsx — tests an internal subcomponent in isolation |
| 2 | test('renders a link to the feed', async () => { |
| 3 | await page.render(<MobileSquareIcons baseUrl="https://example.com" />); |
| 4 | await expect.element(page.getByRole('link', { name: 'MyFeed' })) |
| 5 | .toHaveAttribute('href', 'https://example.com/feed'); |
| 6 | }); |
| 7 | // ...and the same behavior re-tested only for desktop in another file |
Explanation (EN)
Rendering the private MobileSquareIcons subcomponent couples the test to internal structure, and splitting the same assertion across per-variant files duplicates intent while leaving the other variant untested.
Objašnjenje (HR)
Renderiranje privatne MobileSquareIcons podkomponente vezuje test uz internu strukturu, a razdvajanje iste tvrdnje po datotekama za pojedine varijante duplicira namjeru i ostavlja drugu varijantu neprotestiranom.
Good example
| 1 | // Header.browser.test.tsx — one suite drives both header variants |
| 2 | describe.each(['desktop', 'mobile'])('%s header', (variant) => { |
| 3 | test('exposes a link to the feed, flagged new', async () => { |
| 4 | await renderHeader({ variant }); |
| 5 | const link = page.getByRole('link', { name: 'MyFeed' }); |
| 6 | await expect.element(link).toHaveAttribute('href', 'https://example.com/feed'); |
| 7 | await expect.element(link).toHaveTextContent('NEW'); |
| 8 | }); |
| 9 | }); |
Explanation (EN)
One parameterized suite exercises the public header for both variants, asserts on user-visible roles/text, and stays decoupled from which internal component happens to render the link.
Objašnjenje (HR)
Jedan parametrizirani skup testira javni header za obje varijante, provjerava korisniku vidljive uloge/tekst i ostaje odvojen od toga koja interna komponenta renderira link.
Exceptions / Tradeoffs (EN)
A dedicated test for a subcomponent is fine when that subcomponent is a genuinely reusable public unit with its own contract, not an internal rendering detail.
Iznimke / Tradeoffi (HR)
Namjenski test za podkomponentu je u redu kada je ta podkomponenta stvarno ponovno upotrebljiva javna jedinica s vlastitim ugovorom, a ne interni detalj renderiranja.