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).
Don't wrap a whole test file in a redundant describe block
Skip the single top-level describe that just names the module; modern runners print the file. Use describe only for meaningful groups.
Bad example
| 1 | describe('userService', () => { |
| 2 | test('creates a user', () => { /* ... */ }); |
| 3 | test('rejects duplicates', () => { /* ... */ }); |
| 4 | }); |
Explanation (EN)
The describe adds an indentation level and names nothing the file path doesn't already convey on a failure.
Objašnjenje (HR)
Describe dodaje razinu uvlacenja i ne imenuje nista sto putanja datoteke vec ne prenosi pri padu testa.
Good example
| 1 | test('creates a user', () => { /* ... */ }); |
| 2 | test('rejects duplicates', () => { /* ... */ }); |
| 3 |
|
| 4 | describe('when the user is suspended', () => { |
| 5 | // grouped because these tests share a meaningful context |
| 6 | test('blocks login', () => { /* ... */ }); |
| 7 | }); |
Explanation (EN)
Top-level tests stay flat; describe is reserved for a subset that shares context worth naming, where the grouping actually earns its keep.
Objašnjenje (HR)
Testovi na najvisoj razini ostaju ravni; describe je rezerviran za podskup koji dijeli kontekst vrijedan imenovanja, gdje grupiranje stvarno ima smisla.
Exceptions / Tradeoffs (EN)
Keep describe when grouping a genuine subset of tests that share setup or a named scenario you don't want to repeat in every test name.
Iznimke / Tradeoffi (HR)
Zadrzi describe kada grupiras stvaran podskup testova koji dijele setup ili imenovani scenarij koji ne zelis ponavljati u svakom imenu testa.