From c41bc5a99d95766630c5c6a7ebc3c2723308e5ad Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 8 May 2026 07:29:32 -0400 Subject: [PATCH] fix(web/test): mount ToastHost in vitest setup so toast assertions resolve W-T3 (617477b) consolidated toast rendering into a single mounted in +layout.svelte, but page-level tests render components without the layout, so screen.getByTestId('toast') and role=status queries broke. Mount ToastHost in beforeEach (auto-cleaned by svelteTesting()) and reset the store with clearToast() in afterEach so toasts can't leak between tests. Co-Authored-By: Claude Opus 4.7 (1M context) --- web/vitest.setup.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/web/vitest.setup.ts b/web/vitest.setup.ts index 8ffcfdd9..a953959e 100644 --- a/web/vitest.setup.ts +++ b/web/vitest.setup.ts @@ -1,4 +1,8 @@ import '@testing-library/jest-dom/vitest'; +import { beforeEach, afterEach } from 'vitest'; +import { render } from '@testing-library/svelte'; +import ToastHost from './src/lib/components/ToastHost.svelte'; +import { clearToast } from './src/lib/stores/toast.svelte'; // Node 25 ships a partial localStorage global that lacks getItem/setItem/clear // unless launched with --localstorage-file. jsdom sees Node's global and skips @@ -21,3 +25,20 @@ if (typeof window !== 'undefined') { Object.defineProperty(window, 'localStorage', { configurable: true, value: memLocal }); Object.defineProperty(window, 'sessionStorage', { configurable: true, value: memSession }); } + +// W-T3 moved toast rendering out of per-page markup into a single +// mounted in +layout.svelte. Tests render individual pages +// without the layout, so we mount ToastHost here so `pushToast()` calls +// from page code surface in the DOM the same way they do in production. +// `render()` from @testing-library/svelte registers auto-cleanup via the +// svelteTesting() vite plugin, so the host gets unmounted between tests +// alongside whatever component the test itself rendered. clearToast() +// resets the module-scope store state so a stale toast from one test +// can't leak into another. +beforeEach(() => { + render(ToastHost); +}); + +afterEach(() => { + clearToast(); +});