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).
testing ruleP2universalStack: Testing
testingstructure
Write failure and validation tests before the happy path
Order a test suite so error, validation and edge cases come before the success case. Tests run top-to-bottom in the order the code evaluates guards, so leading with failures verifies the guards actually fire before the happy path is reached, and reads as a spec of what the code rejects.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codets
| 1 | describe('register', () => { |
| 2 | it('creates a user', ...); |
| 3 | it('rejects an invalid email', ...); |
| 4 | it('rejects a duplicate', ...); |
| 5 | }); |
Explanation (EN)
The happy path leads; the guards it depends on are asserted afterwards.
Objašnjenje (HR)
Good example
New codets
| 1 | describe('register', () => { |
| 2 | it('rejects an invalid email', ...); |
| 3 | it('rejects a duplicate', ...); |
| 4 | it('creates a user', ...); |
| 5 | }); |
Explanation (EN)
Guards are verified first, mirroring evaluation order, before asserting success.
Objašnjenje (HR)