diff --git a/web/src/lib/stores/theme.svelte.test.ts b/web/src/lib/stores/theme.svelte.test.ts index 42f3aea3..8f493340 100644 --- a/web/src/lib/stores/theme.svelte.test.ts +++ b/web/src/lib/stores/theme.svelte.test.ts @@ -20,7 +20,14 @@ function setupMatchMedia(prefersLight: boolean) { vi.stubGlobal('window', { matchMedia: () => mql }); - return { mql, listeners, fire: (matches: boolean) => listeners.forEach((cb) => cb({ matches })) }; + return { + mql, + listeners, + fire: (matches: boolean) => { + mql.matches = matches; + listeners.forEach((cb) => cb({ matches })); + } + }; } beforeEach(() => { diff --git a/web/src/routes/settings/Appearance.test.ts b/web/src/routes/settings/Appearance.test.ts index a0364a9a..cc58b006 100644 --- a/web/src/routes/settings/Appearance.test.ts +++ b/web/src/routes/settings/Appearance.test.ts @@ -1,16 +1,29 @@ import { describe, expect, test, vi, beforeEach } from 'vitest'; import { render, screen, fireEvent } from '@testing-library/svelte'; -vi.mock('$lib/api/listenbrainz', () => ({ - createLBStatusQuery: () => ({ - subscribe: () => () => {}, - isPending: false, - isError: false, - data: { token_set: false, enabled: false } - }), - createTokenMutation: () => ({ subscribe: () => () => {}, mutate: vi.fn(), isPending: false }), - createEnabledMutation: () => ({ subscribe: () => () => {}, mutate: vi.fn(), isPending: false }) -})); +vi.mock('$lib/api/listenbrainz', () => { + // Mocks must look like a Svelte readable store. The page reads e.g. + // $status.isPending, which is shorthand for "subscribe to status, + // then read .isPending on the emitted value." Returning an object + // that ALSO carries isPending/etc. as bare properties (without a + // working subscribe) makes $status resolve to undefined. + const stub = >(value: T) => ({ + subscribe: (run: (v: T) => void) => { + run(value); + return () => {}; + } + }); + return { + createLBStatusQuery: () => + stub({ + isPending: false, + isError: false, + data: { token_set: false, enabled: false } + }), + createTokenMutation: () => stub({ mutate: vi.fn(), isPending: false }), + createEnabledMutation: () => stub({ mutate: vi.fn(), isPending: false }) + }; +}); vi.mock('@tanstack/svelte-query', async (orig) => { const actual = (await orig()) as Record;