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
matchersjest-domreadability
Assert DOM presence with semantic matchers, not null checks
Use `toBeInTheDocument()` / `toBeEmptyDOMElement()` instead of `expect(el).not.toBeNull()` or `container.firstChild === null`; failures read as intent and the matchers exist in both jest-dom and browser mode.
PR: hegnar-web#4698 FCK-3550 Drive ad suppression from the article flagCreated: Sep 7, 2026
Bad example
Old codets
| 1 | expect(container.querySelector('.c-ad')).not.toBeNull(); |
| 2 | expect(container.firstChild).toBeNull(); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | expect(container.querySelector('.c-ad')).toBeInTheDocument(); |
| 2 | expect(container).toBeEmptyDOMElement(); |
Explanation (EN)
Objašnjenje (HR)