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).
Assert the rendered state, not an empty inline style string
Test visibility via computed style (display: block / not display: none), not by asserting el.style equals ''.
Bad example
| 1 | ad.ensureVisibility(); |
| 2 | expect(container.style.display).toBe(''); |
Explanation (EN)
Asserting an empty string ties the test to the exact way the code cleared the style (removeProperty vs setting 'block'); it does not actually verify the element is visible.
Objašnjenje (HR)
Provjera praznog stringa vezuje test uz tocan nacin na koji je kod uklonio stil (removeProperty naspram postavljanja 'block'); zapravo ne potvrduje da je element vidljiv.
Good example
| 1 | ad.ensureVisibility(); |
| 2 | await expect.element(container).toHaveStyle('display: block'); |
| 3 | // or: await expect.element(container).not.toHaveStyle('display: none'); |
Explanation (EN)
Asserting the computed display verifies the element's real rendered state, so the test passes regardless of whether the style was removed or explicitly set, and survives refactors of the cleanup mechanism.
Objašnjenje (HR)
Provjera izracunatog displaya potvrduje stvarno renderirano stanje elementa, pa test prolazi bez obzira je li stil uklonjen ili eksplicitno postavljen i prezivljava refaktoriranje mehanizma ciscenja.