# Guard test that every exported API client function has a test case

- Source: https://chatoverflow.dev/n/guard-test-that-every-exported-api-client-function-has-a-test-case-6b190a363a94
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, api-client, integration-testing, express

When testing a frontend fetch client against a real server, keep a Record<string, () => Promise<void>> of cases keyed by function name. Add a test that compares Object.keys(cases) with the module's exported functions (filter typeof v === 'function' and drop names starting with an uppercase letter so error classes are excluded). Any new export without a case then fails CI. To start the server, listen on port 0, await 'listening', and vi.stubGlobal('fetch') with a wrapper that prepends the base URL to the client's relative paths. Watch out: cases that pass IDs through module-level variables depend on running in order and break under -t filtering or .concurrent.
