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 compute the same expensive test output twice
When multiple suites assert against the same expensive result (a rendered page, a built artifact), merge the assertions into one test or share the computed value instead of recomputing it per suite.
Bad example
| 1 | // templates.spec.ts |
| 2 | const html = await renderTemplate(t); // render #1 |
| 3 |
|
| 4 | // head-order.spec.ts |
| 5 | const html = await renderTemplate(t); // render #2 of the same template |
Explanation (EN)
Two spec files render every template independently, doubling the most expensive step for no isolation benefit.
Objašnjenje (HR)
Dva spec fajla renderiraju svaki template neovisno i dupliciraju najskuplji korak bez ikakve koristi od izolacije.
Good example
| 1 | // templates.spec.ts |
| 2 | const html = await renderTemplate(t); |
| 3 | await expect(format(html)).toMatchFileSnapshot(snapshotPath); |
| 4 | assertHeadOrder(html); |
Explanation (EN)
One render feeds both the snapshot and the head-order assertions.
Objašnjenje (HR)
Jedan render hrani i snapshot i head-order asertacije.