Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Remove assertions that duplicate existing coverage
Remove repeated checks of the same property when existing assertions or representative snapshots already cover it. Preserve checks that exercise distinct behavior or missing scenarios.
Bad example
| 1 | expect(html).toMatchSnapshot(); |
| 2 | expect(html).toContain('<link rel="stylesheet" href="/page.css">'); |
Explanation (EN)
When the same populated output is already reviewed in the snapshot, this exact-format string adds a second brittle representation of the same property.
Objašnjenje (HR)
Ako se isti popunjeni izlaz već pregledava u snapshotu, string točnog formata dodaje drugi krhki prikaz istog svojstva.
Good example
| 1 | const html = renderPage({ styles: ['/page.css'] }); |
| 2 | expect(html).toMatchSnapshot(); |
Explanation (EN)
Representative fixtures make the chosen assertion cover the intended stylesheet output. Keep separate cases for different branches.
Objašnjenje (HR)
Reprezentativni ulazi osiguravaju da odabrana provjera pokriva namjeravani izlaz stilova. Zadrži zasebne slučajeve za različite grane.
Notes (EN)
Apply when reviewing repeated assertions or temporary validation added beside an established snapshot. Inspect the snapshot contents before removing targeted checks. Empty fixtures may omit the very property the test should cover. Prefer semantic assertions when exact HTML formatting is irrelevant. Identical consecutive assertions add no coverage.
Bilješke (HR)
Primijeni pri provjeri ponovljenih tvrdnji ili privremene validacije uz postojeći snapshot. Prije uklanjanja ciljanih provjera pregledaj sadržaj snapshota. Prazni ulazi mogu izostaviti upravo svojstvo koje test treba pokriti. Prednost daj semantičkim provjerama kad točan format HTML-a nije bitan. Jednake uzastopne tvrdnje ne dodaju pokrivenost.
Exceptions / Tradeoffs (EN)
Snapshots and targeted assertions may coexist when they protect distinct contracts or make an important invariant explicit. Do not remove an uncovered publication, variant, error case or negative assertion merely because another case has a snapshot.
Iznimke / Tradeoffi (HR)
Snapshot i ciljane tvrdnje mogu postojati zajedno kad štite različite ugovore ili ističu važnu invarijantu. Nemoj ukloniti nepokrivenu varijantu, slučaj greške ili negativnu tvrdnju samo zato što drugi slučaj ima snapshot.