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', {
|
vi.stubGlobal('window', {
|
||||||
matchMedia: () => mql
|
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(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
@@ -1,16 +1,29 @@
|
|||||||
import { describe, expect, test, vi, beforeEach } from 'vitest';
|
import { describe, expect, test, vi, beforeEach } from 'vitest';
|
||||||
import { render, screen, fireEvent } from '@testing-library/svelte';
|
import { render, screen, fireEvent } from '@testing-library/svelte';
|
||||||
|
|
||||||
vi.mock('$lib/api/listenbrainz', () => ({
|
vi.mock('$lib/api/listenbrainz', () => {
|
||||||
createLBStatusQuery: () => ({
|
// Mocks must look like a Svelte readable store. The page reads e.g.
|
||||||
subscribe: () => () => {},
|
// $status.isPending, which is shorthand for "subscribe to status,
|
||||||
isPending: false,
|
// then read .isPending on the emitted value." Returning an object
|
||||||
isError: false,
|
// that ALSO carries isPending/etc. as bare properties (without a
|
||||||
data: { token_set: false, enabled: false }
|
// working subscribe) makes $status resolve to undefined.
|
||||||
}),
|
const stub = <T extends Record<string, unknown>>(value: T) => ({
|
||||||
createTokenMutation: () => ({ subscribe: () => () => {}, mutate: vi.fn(), isPending: false }),
|
subscribe: (run: (v: T) => void) => {
|
||||||
createEnabledMutation: () => ({ subscribe: () => () => {}, mutate: vi.fn(), isPending: false })
|
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) => {
|
vi.mock('@tanstack/svelte-query', async (orig) => {
|
||||||
const actual = (await orig()) as Record<string, unknown>;
|
const actual = (await orig()) as Record<string, unknown>;
|
||||||
|
|||||||
Reference in New Issue
Block a user