From aaa6fa15d6cccb554f80f95c6abdf5726b307c96 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 8 Oct 2026 14:18:44 -0400 Subject: [PATCH] test(web): import history components after their mocks (M494) HistoryRow now renders LikeButton, and both history test files imported the component before the likes mock helper. LikeButton then loaded while emptyLikesMock was still uninitialised, and the suites failed at import. Every other suite imports components after its mocks. Co-Authored-By: Claude Opus 5.5 --- web/src/lib/components/HistoryRow.test.ts | 5 ++++- web/src/routes/library/history/page.test.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/web/src/lib/components/HistoryRow.test.ts b/web/src/lib/components/HistoryRow.test.ts index 5dfcbdaf..a37f73ae 100644 --- a/web/src/lib/components/HistoryRow.test.ts +++ b/web/src/lib/components/HistoryRow.test.ts @@ -1,6 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { render, screen, fireEvent } from '@testing-library/svelte'; -import HistoryRow from './HistoryRow.svelte'; import type { HistoryEvent } from '#lib/api/history.js'; import { makeTrack } from '#test-utils/fixtures/track.js'; import { emptyLikesMock } from '../../test-utils/mocks/likes'; @@ -27,6 +26,10 @@ vi.mock('#lib/api/likes.js', () => emptyLikesMock()); vi.mock('#lib/api/quarantine.js', () => emptyQuarantineMock()); +// Imported after the mocks: the component pulls in LikeButton, whose +// mocked module must already be initialised. +import HistoryRow from './HistoryRow.svelte'; + const sampleTrack = makeTrack({ title: 'Song Title', album_title: 'Album', diff --git a/web/src/routes/library/history/page.test.ts b/web/src/routes/library/history/page.test.ts index 9777edcf..481d771a 100644 --- a/web/src/routes/library/history/page.test.ts +++ b/web/src/routes/library/history/page.test.ts @@ -1,6 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { render, screen } from '@testing-library/svelte'; -import HistoryPage from './+page.svelte'; import type { HistoryEvent, HistoryResponse } from '#lib/api/history.js'; import { makeTrack } from '#test-utils/fixtures/track.js'; import { emptyLikesMock } from '../../../test-utils/mocks/likes'; @@ -63,6 +62,10 @@ vi.mock('#lib/branding.js', () => ({ pageTitle: (s: string) => `Minstrel ยท ${s}` })); +// Imported after the mocks: the component pulls in LikeButton, whose +// mocked module must already be initialised. +import HistoryPage from './+page.svelte'; + describe('library/history page', () => { beforeEach(() => { mockData = { pages: [] };