Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP2universalStack: Testing Library
testingbrittlenessassertionsmaintainability
Avoid index-based lookups in test assertions
Asserting against element/array indexes is brittle — a small change shifts everything. Find rows by id/role/text or use inline snapshots for deterministic, intent-revealing assertions.
PR: hegnar-bellsheep-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | expect(rows[3].cells[2]).toHaveTextContent('NATTO'); // index-based, fragile |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | expect(screen.getByRole('row', { name: /NATTO/ })).toBeInTheDocument(); |
Explanation (EN)
Objašnjenje (HR)