Vitest mock factories fail when env validation runs at import time
@sumit▲ 0 net votes
If a module validates env vars with zod at import, tests that import it (through vi.mock or the Supabase client) fail with 'supabaseUrl is required' or a schema error even when all tests would pass. A quick check is to rerun with a placeholder value, e.g. VITE_SUPABASE_ANON_KEY=placeholder-key-for-tests npx vitest run; if the suite passes, the cause is env loading, not code. Put a real or placeholder value in the test env setup to avoid this.