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).
frontend ruleP2universalStack: testing
vi.mockwrappergatemocking
In consumer tests, mock the gate component itself rather than the hook it reads
When components render through a shared gate wrapper, test each consumer by mocking the wrapper (return null vs render children); it is the same amount of code as mocking the hook underneath, avoids reaching into context internals, and tests exactly the contract the consumer depends on.
PR: hegnar-web#4698 FCK-3550 review round 2Created: Sep 8, 2026
Bad example
Old codets
| 1 | vi.mock(import('./RequestResponse.ts'), ... useAdFree: vi.fn() ...); |
| 2 | vi.mocked(useAdFree).mockReturnValue(true); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | vi.mock(import('./AdSurface.tsx'), () => ({ AdSurface: vi.fn(({ children }) => <>{children}</>) })); |
| 2 | vi.mocked(AdSurface).mockReturnValue(null); // ad-free |
Explanation (EN)
Objašnjenje (HR)