Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Run shared asynchronous test setup in lifecycle hooks
Keep test registration synchronous and put shared asynchronous preparation in beforeAll. Use per-test setup when fixtures are mutable or require isolation.
Bad example
| 1 | describe('document checks', async () => { |
| 2 | const documents = await loadDocuments(); |
| 3 | it('has valid entries', () => expect(documents.every(isValid)).toBe(true)); |
| 4 | }); |
Explanation (EN)
Asynchronous preparation runs during suite registration instead of through the runner lifecycle.
Objašnjenje (HR)
Asinkrona priprema izvršava se tijekom registracije suitea umjesto kroz životni ciklus test runnera.
Good example
| 1 | describe('document checks', () => { |
| 2 | let documents: DocumentFixture[]; |
| 3 | beforeAll(async () => { |
| 4 | documents = await loadDocuments(); |
| 5 | }); |
| 6 | it('has valid entries', () => expect(documents.every(isValid)).toBe(true)); |
| 7 | }); |
Explanation (EN)
The runner registers tests immediately and awaits the shared preparation before executing them.
Objašnjenje (HR)
Runner odmah registrira testove i čeka zajedničku pripremu prije njihova izvršavanja.
Notes (EN)
Use the runner-supported lifecycle for asynchronous fixture loading or expensive shared setup. Identical immutable data can be prepared once instead of repeated per test. Keep describe callbacks synchronous and pair resource acquisition with cleanup hooks where needed.
Bilješke (HR)
Za asinkrono učitavanje fixtureova ili skupu zajedničku pripremu koristi životni ciklus koji podržava runner. Jednaki nepromjenjivi podaci mogu se pripremiti jednom umjesto za svaki test. Describe callback ostavi sinkronim, a zauzimanje resursa poveži s hookom za čišćenje kad je potrebno.
Exceptions / Tradeoffs (EN)
Use beforeEach or fresh factories for mutable or isolated state. Supported dynamic test discovery may require an intentional collection-time mechanism, but do not introduce async describe merely to load shared fixtures.
Iznimke / Tradeoffi (HR)
Za promjenjivo ili izolirano stanje koristi beforeEach ili nove instance iz tvorničke funkcije. Podržano dinamičko otkrivanje testova može zahtijevati namjerni mehanizam pri prikupljanju, ali nemoj uvoditi async describe samo radi zajedničkih fixtureova.