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).
Make the preconditions a test relies on explicit, not implied by defaults
When a test's name or intent depends on a specific input state (e.g. "both fields are set"), set that state explicitly in the test data instead of relying on a factory's current defaults.
Bad example
| 1 | it('keeps the CMS title when both titles are set', () => { |
| 2 | const node = buildArticle(createArticle({ seoTitle: 'SEO title' })); |
| 3 | // title relies on createArticle's current default value |
| 4 | }); |
Explanation (EN)
The test name claims 'both titles are set', but only one is set explicitly — the other is whatever the factory currently defaults to. If that default ever changes, the test silently stops testing what it claims to.
Objašnjenje (HR)
Naziv testa tvrdi da su 'oba naslova postavljena', ali samo jedan je eksplicitno postavljen — drugi ovisi o trenutnom defaultu tvorničke funkcije. Ako se default promijeni, test tiho prestaje testirati ono što tvrdi.
Good example
| 1 | it('keeps the CMS title when both titles are set', () => { |
| 2 | const node = buildArticle(createArticle({ title: 'CMS title', seoTitle: 'SEO title' })); |
| 3 | }); |
Explanation (EN)
Both relevant fields are set explicitly in the test, so the scenario it claims to cover is guaranteed regardless of factory defaults.
Objašnjenje (HR)
Oba relevantna polja eksplicitno su postavljena u testu, pa je scenarij koji test tvrdi da pokriva zajamčen bez obzira na defaultne vrijednosti tvornice.