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).
Group repeated style assertions with toHaveStyle instead of one expect per property
Prefer a single toHaveStyle({ ... }) matcher over many individual expect(el.style.x).toBe(...) lines for the same element.
Bad example
| 1 | expect(frame.style.transform).toBe('scale(0.74)'); |
| 2 | expect(frame.style.transformOrigin).toBe('top center'); |
| 3 | expect(placement.style.alignItems).toBe('flex-start'); |
Explanation (EN)
Asserting each style property in its own expect is repetitive and scatters a single 'the element is laid out like X' intent across several lines.
Objašnjenje (HR)
Provjera svakog stilskog svojstva u zasebnom expect-u je repetitivna i razbacuje jednu namjeru 'element je rasporeden ovako' po vise redaka.
Good example
| 1 | expect(frame).toHaveStyle({ |
| 2 | transform: 'scale(0.74)', |
| 3 | transformOrigin: 'top center', |
| 4 | }); |
| 5 | expect(placement).toHaveStyle({ alignItems: 'flex-start' }); |
Explanation (EN)
A single toHaveStyle matcher checks several properties at once, expressing one layout expectation and reducing boilerplate.
Objašnjenje (HR)
Jedan toHaveStyle matcher provjerava vise svojstava odjednom, izrazavajuci jedno ocekivanje rasporeda i smanjujuci boilerplate.
Exceptions / Tradeoffs (EN)
When a value isn't an exact match (e.g. a computed float you assert with toBeCloseTo), keep a targeted assertion for that property rather than forcing it into toHaveStyle.
Iznimke / Tradeoffi (HR)
Kad vrijednost nije tocno podudaranje (npr. izracunati float koji provjeravas s toBeCloseTo), zadrzi ciljanu tvrdnju za to svojstvo umjesto da je guras u toHaveStyle.