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).
Use inline snapshots for long, tedious expected values
Prefer toMatchInlineSnapshot over toBe/toEqual when the expected value is long enough that hand-typing it invites transcription errors.
Bad example
| 1 | expect(result.url).toBe('https://dev.example.com/header?v=11&token=abc123def456&sig=...'); |
Explanation (EN)
Long literals typed by hand are easy to get subtly wrong and noisy to update when the expected output changes.
Objašnjenje (HR)
Dugacki literali pisani rukom lako se suptilno pogrijese i bucni su za azuriranje kada se ocekivani izlaz promijeni.
Good example
| 1 | expect(result.url).toMatchInlineSnapshot(); |
| 2 | // runner fills in: |
| 3 | // expect(result.url).toMatchInlineSnapshot('"https://dev.example.com/header?v=11&token=abc123def456&sig=..."'); |
Explanation (EN)
The test runner writes and updates the literal for you, eliminating transcription mistakes while keeping the expectation right next to the assertion.
Objašnjenje (HR)
Test runner sam upisuje i azurira literal, cime se uklanjaju greske prepisivanja, a ocekivanje ostaje uz sam assertion.
Exceptions / Tradeoffs (EN)
For short, meaningful values prefer an explicit toBe/toEqual so the intent is readable without running the snapshot.
Iznimke / Tradeoffi (HR)
Za kratke, smislene vrijednosti radije koristi eksplicitni toBe/toEqual da je namjera citljiva i bez pokretanja snapshota.