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).
fullstack ruleP2universalStack: javascript
testingvitestjestdry
Use test.each for tables of similar test cases
When several tests differ only by input/expected values, drive them with test.each instead of copy-pasting near-identical test bodies.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | it('a', () => expect(f(1)).toBe(2)); |
| 2 | it('b', () => expect(f(2)).toBe(4)); |
| 3 | it('c', () => expect(f(3)).toBe(6)); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | test.each([ |
| 2 | [1, 2], |
| 3 | [2, 4], |
| 4 | [3, 6], |
| 5 | ])('f(%i) === %i', (input, expected) => { |
| 6 | expect(f(input)).toBe(expected); |
| 7 | }); |
Explanation (EN)
Objašnjenje (HR)