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: universal
testingfixturesreadabilitytest-isolation
Build test fixtures inside the test that uses them, not by mutating shared setup
Define data a single test needs within that test rather than placing it in shared beforeEach setup and mutating it later; minor duplication is preferable to coupled, mutated fixtures.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | let simplifiedTestData; |
| 2 | beforeEach(() => { simplifiedTestData = { /* ... */ }; }); |
| 3 |
|
| 4 | it('handles broken data', () => { |
| 5 | simplifiedTestData.structure = undefined; // mutate shared fixture |
| 6 | expect(parse(simplifiedTestData)).toEqual([]); |
| 7 | }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | it('handles broken data', () => { |
| 2 | const broken = { dataSets: [] }; // local to the test that needs it |
| 3 | expect(parse(broken)).toEqual([]); |
| 4 | }); |
Explanation (EN)
Objašnjenje (HR)