Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use clearly synthetic hosts in mocked network tests
When a unit test mocks network transport and the hostname is not part of the behavior under test, use an obviously synthetic example endpoint instead of a real development or production service URL.
Bad example
| 1 | import { vi } from 'vitest'; |
| 2 |
|
| 3 | export const developmentApiUrl = 'https://example.com'; |
| 4 | export const fetchMock = vi.fn().mockResolvedValue({ |
| 5 | json: async () => ({ items: [] }), |
| 6 | }); |
Explanation (EN)
The fixture is named after a real deployment environment even though transport is mocked. The example.com address stands in for the copied development-service hostname.
Objašnjenje (HR)
Testni podatak nazvan je prema stvarnom okruženju iako je transport mockan. Adresa example.com predstavlja kopirani hostname razvojnog servisa.
Good example
| 1 | import { vi } from 'vitest'; |
| 2 |
|
| 3 | export const testApiUrl = 'https://example.org'; |
| 4 | export const fetchMock = vi.fn().mockResolvedValue({ |
| 5 | json: async () => ({ items: [] }), |
| 6 | }); |
Explanation (EN)
The host makes its fixture role clear and does not couple the test to an environment name. Wire the mock into the code under test and reject unexpected real requests.
Objašnjenje (HR)
Host jasno označava testni podatak i ne veže test uz naziv okruženja. Poveži mock s kodom koji se testira i odbij neočekivane stvarne zahtjeve.
Notes (EN)
Apply to mocked service tests where only URL construction or response handling matters. Keep the scheme, path and query shape required by the behavior while making the hostname clearly illustrative. A fake-looking URL alone does not prevent network calls. The test must actually intercept or inject transport and handle unmatched requests deliberately.
Bilješke (HR)
Primijeni u mockanim testovima servisa kada su bitni sastavljanje URL-a ili obrada odgovora. Sačuvaj protokol, putanju i oblik parametara potrebne za ponašanje, a hostname jasno označi kao primjer. Izmišljeni URL sam po sebi ne sprečava mrežne pozive. Test mora stvarno presresti ili ubrizgati transport i jasno obraditi nepokrivene zahtjeve.
Exceptions / Tradeoffs (EN)
Use realistic hostnames when domain routing, allowlists, cookies or origin validation are the actual contract under test. Explicitly configured integration or end-to-end tests may contact a dedicated test service. Do not replace hosts in such tests without preserving their purpose.
Iznimke / Tradeoffi (HR)
Koristi realistične hostove kada se testiraju usmjeravanje prema domeni, dopuštene domene, kolačići ili provjera origina. Izričito konfigurirani integracijski ili end-to-end testovi mogu kontaktirati namjenski testni servis. Ne zamjenjuj njihove hostove bez očuvanja svrhe.