fix(web/m7-362): repair Vitest fixtures (matchMedia.fire, listenbrainz mock)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
@@ -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 = <T extends Record<string, unknown>>(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<string, unknown>;
|
||||
|
||||
Reference in New Issue
Block a user