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 ruleP2stack specificStack: testing
vitestbrowser-modedata-testidlocators
Give test stubs and probe elements a data-testid so page.getByTestId locators work
In browser-mode tests, mark the element you assert on with data-testid (on the stub or the probe) and query it with page.getByTestId + expect.element, instead of inventing an ad-hoc attribute and reaching for container.querySelector.
PR: hegnar-web#4698 FCK-3550 review round 2Created: Sep 8, 2026
Bad example
Old codets
| 1 | default: () => <div data-name={featureId} /> |
| 2 | // ... |
| 3 | expect(container.querySelector('[data-name="x"]')).toBeInTheDocument(); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | default: () => <div data-testid="zephr-feature" /> |
| 2 | // ... |
| 3 | await expect.element(page.getByTestId('zephr-feature')).toBeInTheDocument(); |
Explanation (EN)
Objašnjenje (HR)