From 4b4ab27e5fb08db8c24648a15e14cfda9f07f321 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Tue, 23 Jun 2026 12:22:04 -0400 Subject: [PATCH] test(web): provide a default Apollo client in vitest setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some components and generated composables resolve the default Apollo client asynchronously (e.g. during teardown, after the triggering test has finished). Even with useQuery mocked, this surfaced ~22 "Apollo client with id default not found" unhandled rejections in the full web suite — reported against unrelated files like Modals.test.ts and DowngradeOs.test.ts — adding noise and risking false positives. Provide a no-op default client (InMemoryCache + a terminating link that emits an empty result) in the global vitest setup so resolveClient never throws, regardless of timing. No network calls; useQuery stays mocked. Full web suite: 64 files / 641 tests pass, zero unhandled rejections. Co-Authored-By: Claude Opus 4.8 --- web/vitest.setup.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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(() => ({