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 ruleP2stack specificStack: typescript
testingvitestmockingtypescript
Mock modules using a dynamic import() reference for path resilience and type safety
Pass import('module') to vi.mock so the mock path follows refactors and you get type safety on the factory.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | vi.mock('../../../../../client/js/utils/hooks/useToast', () => ({ |
| 2 | default: () => ({ toastSuccess, toastError }), |
| 3 | })); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | vi.mock(import('../../../../../client/js/utils/hooks/useToast'), () => ({ |
| 2 | default: () => ({ toastSuccess, toastError }), |
| 3 | })); |
Explanation (EN)
Objašnjenje (HR)