diff --git a/web/vitest.setup.ts b/web/vitest.setup.ts index d8082bca47..a7a48a1cc2 100644 --- a/web/vitest.setup.ts +++ b/web/vitest.setup.ts @@ -1,6 +1,8 @@ import { ref } from 'vue'; import { createPinia, setActivePinia } from 'pinia'; +import { provideApolloClient } from '@vue/apollo-composable'; +import { ApolloClient, ApolloLink, InMemoryCache, Observable } from '@apollo/client/core'; import { beforeEach, vi } from 'vitest'; vi.mock('@vue/apollo-composable', async () => { @@ -20,6 +22,20 @@ vi.mock('@vue/apollo-composable', async () => { }; }); +// Provide a no-op default Apollo client for the whole test run. Even with +// useQuery mocked above, some components and generated composables resolve the +// default client asynchronously (e.g. during teardown, after the test that +// triggered them has finished). Without a provided client, @vue/apollo-composable +// throws "Apollo client with id default not found" as an unhandled rejection, +// polluting unrelated suites. A terminating link that emits an empty result keeps +// any stray operation quiet without making network calls. +provideApolloClient( + new ApolloClient({ + cache: new InMemoryCache(), + link: new ApolloLink(() => Observable.of({ data: {} })), + }) +); + // Mock WebSocket for test environment if (!global.WebSocket) { const mockWebSocket = vi.fn().mockImplementation(() => ({