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).
Annotate shared test fixtures with their source type
Give mock/fixture objects an explicit type derived from the source (e.g. ReturnType<typeof useHook>) and apply it consistently across all test files.
Bad example
| 1 | // one file types it, another does not |
| 2 | const defaultBreakpoint: ReturnType<typeof useBreakpoint> = { |
| 3 | isMobile: false, |
| 4 | isDesktop: false, |
| 5 | }; |
| 6 |
|
| 7 | // elsewhere, untyped |
| 8 | const defaultBreakpoint = { |
| 9 | isMobile: false, |
| 10 | isDesktop: false, |
| 11 | }; |
Explanation (EN)
An untyped fixture silently accepts a wrong shape and inconsistent typing across files means some tests get compile-time protection while others do not.
Objašnjenje (HR)
Netipizirani fixture tiho prihvaca krivi oblik, a nekonzistentno tipiziranje znaci da neki testovi imaju zastitu pri kompajliranju, a drugi ne.
Good example
| 1 | const defaultBreakpoint: ReturnType<typeof useBreakpoint> = { |
| 2 | isMobile: false, |
| 3 | isDesktop: false, |
| 4 | }; |
Explanation (EN)
Deriving the fixture type from the source keeps it in lockstep with the real type: if the hook's return shape changes, the fixture fails to compile until updated.
Objašnjenje (HR)
Izvodjenje tipa fixturea iz izvora drzi ga u koraku sa stvarnim tipom: ako se promijeni oblik povratne vrijednosti hooka, fixture se nece kompajlirati dok se ne azurira.