import { beforeEach, describe, expect, it, vi } from 'vitest' async function loadPlugin() { vi.resetModules() vi.stubGlobal('defineNuxtPlugin', (setup: unknown) => setup) return (await import('../app/plugins/api.client')).default } describe('api plugin', () => { beforeEach(() => { vi.restoreAllMocks() vi.unstubAllGlobals() }) it('creates API clients from runtime config values', async () => { vi.stubGlobal('useRuntimeConfig', () => ({ public: { apiBaseUrl: 'https://api.example.test', apiTimeoutMs: 4321 } })) const plugin = await loadPlugin() const { provide } = plugin() const fetchMock = vi.fn().mockResolvedValue({ status: 'ok' }) vi.stubGlobal('$fetch', fetchMock) const response = await provide.api.example.getHealth() expect(response).toEqual({ status: 'ok' }) expect(fetchMock).toHaveBeenCalledWith('/health', { baseURL: 'https://api.example.test', signal: undefined, timeout: 4321 }) }) })