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).
frontend ruleP2universalStack: testing
testingassertionsdomtesting-libraryreadability
Assert element absence with a semantic matcher, not length checks
Use .not.toBeInTheDocument() to assert an element isn't present instead of checking a queried collection's length.
PR: startsiden/hegnar-bellsheep-web#387Created: Jun 17, 2026
Bad example
Old codets
| 1 | expect(page.getByRole('status').elements()).toHaveLength(0); |
Explanation (EN)
Checking length 0 tests the query result indirectly and produces an opaque failure message about array length.
Objašnjenje (HR)
Provjera duljine 0 testira rezultat upita posredno i daje nejasnu poruku o gresci o duljini niza.
Good example
New codets
| 1 | await expect.element(page.getByRole('status')).not.toBeInTheDocument(); |
Explanation (EN)
The absence matcher states the intent directly and gives a clear, element-oriented failure message.
Objašnjenje (HR)
Matcher za odsutnost izravno iskazuje namjeru i daje jasnu poruku o gresci orijentiranu na element.